高性能ワークスレッドの構築4つの具体的な応用


作業スレッドを継承する特定のタスクスレッド
public class BeenCoverThread extends WorkThread {

    // , 
    private LinkedBlockingQueue beenCoverQueue;

    //taskExecutor  
   //beenCoverQueue  
   public BeenCoverThread (CallInfo callInfo,TaskExecutor taskExecutor, LinkedBlockingQueue beenCoverQueue) {
      super(taskExecutor);
      this.beenCoverQueue= beenCoverQueue;
   }

    // , , 
    public void doTask() throws Exception {
        。。。。
      beenCoverQueue.offer(beenInfo);// 
     。。。。
   }

}

定時タスク定期起動タスク
public class QueryCallTask {
     // 
     private static LinkedBlockingQueue beenCoverQueue = new LinkedBlockingQueue<BeenCoverInfo>();
    
     //    spring 
     private TaskExecutor beenCoverExecutor;

     //       
     public void execute() {
          .......
           beforeExcute();// 
          .......
           for (int i = 0; i < callList.size(); i++) {
                 CallInfo callInfo = callList.get(i);
                 beenCoverExecutor.execute(new BeenCoverThread(
                       callInfo,beenCoverExecutor,beenCoverQueue)
           }
          .......
     }
     
     private void beforeExcute(){
        。。。
     final LinkedBlockingQueue beenCoverQueue2 = new LinkedBlockingQueue(beenCoverQueue);// 
       beenCoverQueue.clear();// 
       .....
       cationDao.batchUpdate(beenCoverQueue2 );// 
     。。。

    }
}