为什么结果会出现负的情况? public class MyThreadTest { public static void main(String[] args) { MyThread m=new MyThread(); Thread t1=new Thread(m,"线程1"); Thread t2=new Thread(m,"线程2"); Thread t3=new Thread(m,"线程3"); Thread t4=new Thread(m,"线程4"); t1.start(); t2.start(); t3.start(); t4.start();} }class MyThread implements Runnable{ private int sum=10; private Object lock=new Object(); @Overridepublic void run() { while(sum>0) { //锁 synchronized (lock) { System.out.println(Thread.currentThread().getName()+" "+sum); sum--; } } } }
慕盖茨4494581
相关分类