@Override
public void run() {
while (count > 1) {
cal();
}
}
private synchronized void cal() {
try {
Thread.sleep(10);
} catch (Exception e) {
}
count--;
System.out.println(Thread.currentThread().getName() + "," + count);
}
public static void main(String[] args) {
ThreadCount threadCount = new ThreadCount();
Thread thread1 = new Thread(threadCount);
Thread thread2 = new Thread(threadCount);
thread1.start();
thread2.start();
}
synchronized在方法上锁this , new Thread(threadCount); 是两个不同的对象了 ,他是怎么锁住的??