📄 deadlockfree.java
字号:
import java.awt.event.*;import java.awt.*;public class DeadlockFree{ Account acct1, acct2; public DeadlockFree(int amt1, int amt2) { acct1 = new Account(amt1, "account one"); acct2 = new Account(amt2, "account two");/* The first transaction is done as before. */ Thread thread1 = new Thread(new TransferAtoB(acct1, acct2, 50)); thread1.setName("Thread 1"); thread1.start(); System.out.println(thread1.getName()+" starting");/* The second transaction is now placed on the event queue using *//* the invokeAndWait() method. */ EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); try { System.out.println("ActiveEvent dispatched"); eq.invokeAndWait(new TransferAtoB(acct2, acct1, 75)); } catch (Exception e) {} } public static void main(String args[]) { DeadlockFree demo = new DeadlockFree(100, 200); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -