⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deadlockqueue.java

📁 java的消息队列
💻 JAVA
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -