public class SynchronizeRetreenTest extends Thread {
int i = 1;
public synchronized void doSomething() {
while (i < 10) {
System.out.println("-------" + i);
System.out.println(Thread.currentThread());
i++;
doSomething();
}
}
@Override
public void run() {
doSomething();
}
public static void main(String[] args) {
new SynchronizeRetreenTest().start();
}
}
如果synchronized为不可重入那么会进入死循环,用子父类其实不能验证是否可以重入因为根本不是同一把锁
时间: 2024-10-16 05:27:55