deadlockfree.java

来自「《java事件处理指南》一书的代码,好东西」· Java 代码 · 共 38 行

JAVA
38
字号
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 + =
减小字号Ctrl + -
显示快捷键?