deadlockqueue.java
来自「Effective Java 中文版 侯捷译配套代码」· Java 代码 · 共 27 行
JAVA
27 行
// Page 198
class DeadlockQueue extends WorkQueue {
protected void processItem(final Object workItem)
throws InterruptedException {
// Create a new thread that returns workItem to queue
Thread child = new Thread() {
public void run() { enqueue(workItem); }
};
child.start();
child.join(); // Deadlock!
// Will never print (unless open call version of WorkerThread is used
System.out.println(workItem);
}
public static void main(String[] args) throws InterruptedException {
WorkQueue queue = new DeadlockQueue();
for (int i = 0; i < args.length; i++)
queue.enqueue(args[i]);
// Let items print for a while and then stop the queue
Thread.sleep(1000);
queue.stop();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?