标签:cat catch JDK9 rac 一起 deadlock imp print nts
package lock;
public class DeadLock {
public static Integer l = 5;
public static Integer r = 6;
public static void main(String[] args) {
new Thread(new Thread4()).start();
new Thread(new Thread3()).start();
}
}
class Thread3 implements Runnable{
@Override
public void run() {
synchronized (DeadLock.l){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (DeadLock.r){
System.out.println("Thread3 is running");
}
}
}
}
class Thread4 implements Runnable{
@Override
public void run() {
synchronized (DeadLock.r){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (DeadLock.l){
System.out.println("Thread4 is running");
}
}
}
}
利用jdk自带的jvisualvm进行测试,jdk9之后好像就不和jdk捆绑在一起了(在命令行输入jvisualvm)
两个线程互相拥有对方想要的东西
标签:cat catch JDK9 rac 一起 deadlock imp print nts
原文地址:https://www.cnblogs.com/cstdio1/p/12240815.html