标签:tor nts 使用方法 OLE fixed 而且 this his code
// 固定声明10个线程
private ExecutorService executorService = Executors.new FixedThreadPool(10);
private ThreadPoolExecutor executor = (ThreadPoolExecutor)executorService;
// 使用队列插入数据,后面如果改造成批处理之类的也好执行
private LinkedBlockingDeque<DataModel> queue = new LinkedBlockingDeque<DataModel>();
private void insertRecord(DataModel dataModel){
queue.add(queryModel);
InsertRecordThread task = new InsertRecordThread(jjgExamQuesLoadDao, queue);
executor.execute(task);
}
// 这里不用executor.shutdown(),关闭线程池 , 因为线程池一直开着,没有就不会启用,用就可以直接执行, 不要将线程池关闭。
public class InsertRecordThread implements Runnable{
private JjgExamQuesLoadDao jjgExamQuesLoadDao;
private LinkedBlockingDeque<DataModel> queue;
public InsertRecordThread(JjgExamQuesLoadDao jjg , LinkedBlockingDeque<DataModel> queue){
this.jjgExamQuesLoadDao = jjg;
this.queue = queue;
}
public void run(){
try{
DataModel event = queue.poll();
jjgExamQuesLoadDao.insertAnswerRecord(event);
}catch(Exception e){
e.printStackTrace();
}
}
}
标签:tor nts 使用方法 OLE fixed 而且 this his code
原文地址:https://www.cnblogs.com/eian/p/11478475.html