📄 vmdeadlock.java
字号:
package org.jgroups.tests;
import org.jgroups.util.Util;
/**
* @author Bela Ban
* @version $Id$
*/
public class VMDeadlock {
static final Object mutex_one=new Object();
static final Object mutex_two=new Object();
public static void main(String[] args) throws InterruptedException {
new VMDeadlock().start();
}
private void start() throws InterruptedException {
MyThreadOne t1=new MyThreadOne();
MyThreaTwo t2=new MyThreaTwo();
t1.start();
t2.start();
t1.join();
t2.join();
}
static class MyThreadOne extends Thread {
public void run() {
synchronized(mutex_one) {
Util.sleep(2000);
synchronized(mutex_two) {
// we won't get here
System.out.println("acquired 2");
}
}
}
}
static class MyThreaTwo extends Thread {
public void run() {
synchronized(mutex_two) {
Util.sleep(2000);
synchronized(mutex_one) {
// we won't get here
System.out.println("acquired 1");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -