holmos.webtest.junitextentions.threadpool.HolmosThreadPoolExecutor Maven / Gradle / Ivy
package holmos.webtest.junitextentions.threadpool;
import holmos.webtest.basetools.HolmosBaseTools;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author 吴银龙([email protected])
* */
public class HolmosThreadPoolExecutor extends ThreadPoolExecutor{
/**记录任务总数*/
private volatile int taskCount;
public HolmosThreadPoolExecutor(int nThreads,int taskCount){
super(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue());
this.taskCount=taskCount;
}
@Override
protected void afterExecute(Runnable r, Throwable t) {
synchronized (this) {
taskCount--;
}
}
@Override
protected void beforeExecute(Thread t, Runnable r) {
}
public void waitForCompleted(){
while(taskCount>0){
HolmosBaseTools.sleep(50);
}
}
}