package testthread;
public class TestDeadLock {
static StringBuffer sb1 = new StringBuffer();
static StringBuffer sb2 = new StringBuffer();
public static void main(String[] args) {
new Thread(){
@SuppressWarnings("static-access")
public void run(){
synchronized (sb1) {
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sb1.append("a");
synchronized (sb2) {
sb2.append("b");
System.out.println(sb1);
System.out.println(sb2);
}
}
}
}.start();
new Thread(){
public void run(){
synchronized (sb2) {
sb1.append("c");
synchronized (sb1) {
sb2.append("d");
System.out.println(sb1);
System.out.println(sb2);
}
}
}
}.start();
}
}
Java多线程死锁问题测试
最新推荐文章于 2023-01-18 09:59:51 发布