protected void afterExecute(Runnable r, Throwable t) {
// TODO Auto-generated method stub
super.afterExecute(r, t);
synchronized (this) {
//System.out.println("自动调用了....afterEx 此时getActiveCount()值:"+ this.getActiveCount());
if (this.getActiveCount() == 1)// 已执行完任务之后的最后一个线程
{
this.hasFinish = true;
this.notify();
}// if
num++;
this.updateDisplay(this.getActiveCount());
this.notifyAll();
}// synchronized
}
public void isEndTask() {
synchronized (this) {
while (this.hasFinish == false) {
//System.out.println("等待线程池所有任务结束: wait...");
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
写在线程池里头,
public class MyThreadPool extends ThreadPoolExecutor