📄 deadlock.java
字号:
public class Deadlock { public static void main(String[] args) { final Object resource1 = "resource1"; final Object resource2 = "resource2"; Thread t1 = new Thread() { public void run() { synchronized(resource1) { System.out.println("Thread 1: locked resource 1"); try { Thread.sleep(50); } catch (InterruptedException e) {} synchronized(resource2) { System.out.println("Thread 1: locked resource 2"); } } } }; Thread t2 = new Thread() { public void run() { synchronized(resource2) { System.out.println("Thread 2: locked resource 2"); try { Thread.sleep(50); } catch (InterruptedException e) {} synchronized(resource1) { System.out.println("Thread 2: locked resource 1"); } } } }; t1.start(); t2.start(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -