deadlock.java
来自「《java事件处理指南》一书的代码,好东西」· Java 代码 · 共 37 行
JAVA
37 行
import java.awt.event.*;import java.awt.*;public class Deadlock{ Account acct1, acct2; public Deadlock(int amt1, int amt2) {/* Two Account objects are created */ acct1 = new Account(amt1, "account one"); acct2 = new Account(amt2, "account two");/* Two transactions are executed as separate threads. The first *//* transfers money from Account acct1 to Account acct2. The *//* second transaction transfers money from acct2 to acct1. */ Thread thread1 = new Thread(new TransferAtoB(acct1, acct2, 50)); thread1.setName("Thread 1"); thread1.start(); System.out.println(thread1.getName()+" started"); Thread thread2 = new Thread(new TransferAtoB(acct2, acct1, 75)); thread2.setName("Thread 2"); thread2.start(); System.out.println(thread2.getName()+" started"); } public static void main(String args[]) { Deadlock demo = new Deadlock(100, 200); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?