public class Day1_ClassTest2 {
public static void main(String[] args) throws IOException {
shangche sc = new shangche();
new Thread(sc, "线程一").start();
new Thread(sc, "线程二").start();
}
}
class shangche implements Runnable {
int person = 70;
Object o = new Object();
public void run() {
while (person>0) {
synchronized (o) {
if (person <= 0) {
return;
}
System.out.println(Thread.currentThread().getName() + "自减"+--person);
}