原理:开启线程,并实现Callable接口
一、线程池
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 线程池
*
* @author ht
*
*/
public class ThreadPoolEx {
public static ThreadPoolExecutor tPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(3);
/**
* 初始化线程池
*
*/
public ThreadPoolEx() {
}
public static ThreadPoolExecutor getInstance() {
if (tPool == null) {
tPool = (ThreadPoolExecutor) Executors.newCachedThreadPool();
}
return tPool;
}
}
二、代码执行
private ThreadPoolExecutor pool = ThreadPoolEx.getInstance();
/**
* 循环--拉取并存库
* @param totalPages
* @param startDate
* @param endDate