All Downloads are FREE. Search and download functionalities are using the official Maven repository.

holmos.webtest.junitextentions.threadpool.HolmosThreadPoolExecutor Maven / Gradle / Ivy

There is a newer version: 1.0.2u10
Show newest version
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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy