poolablethread.java

来自「21天学通java的示例程序源代码」· Java 代码 · 共 38 行

JAVA
38
字号
//PoolableThread.javapackage com.wrox.threadpool;class PoolableThread extends Thread {  Runnable task = null;  ThreadPool pool;  PoolableThread(ThreadPool pool) {    this.pool = pool;  }  synchronized void setTask(Runnable task) {    this.task = task;    notify();  }   synchronized void executeTasks() {    for (; ; ) {      try {        if (task == null) {          wait();        }       } catch (InterruptedException ex) {        // Interrupted      }       task.run();      task = null;      pool.free(this);    }   }   public void run() {    executeTasks();  } }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?