📄 deadlockdemo.java
字号:
//DeadlockDemo.javaimport java.lang.*;import java.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class DeadlockDemo extends MIDlet implements Runnable{ private Display display; A a = new A(); B b = new B(); public DeadlockDemo() { //display = Display.getDisplay(this); Thread.currentThread().setPriority(8); Thread t = new Thread(this,"RacingThread"); t.start(); a.foo(b); System.out.println("Back in main thread"); } public void run() { b.bar(a); System.out.println("Back in the other thread"); } protected void startApp() { //display.setCurrent(); new DeadlockDemo(); } protected void pauseApp(){} protected void destroyApp(boolean unconditional){}}class A{ synchronized void foo(B b) { String name = Thread.currentThread().getName(); System.out.println(name + "entered A.foo"); try{ Thread.sleep(1000); }catch(Exception e){ System.out.println("A Interrupted"); } System.out.println(name + "trying to call B.last()"); b.last(); } synchronized void last() { System.out.println("Inside A.last"); }}class B{ synchronized void bar(A a) { String name = Thread.currentThread().getName(); System.out.println(name + "entered B.bar"); try{ Thread.sleep(1000); }catch(Exception e){ System.out.println("B Interrupted"); } System.out.println(name + "trying to call A.last()"); a.last(); } synchronized void last() { System.out.println("Inside B.last"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -