线程池 (V2.0)

XXL-JOB v2.5.0 | 分布式任务调度平台 XXL-JOB是一个轻量级分布式任务调度平台,其核心设计目标是开发迅速、学习简单、轻量级、易扩展。现已开放源代码并接入多家公司线上产品线,开箱即用。 阅读详情

http://www.cnjbb.org/thread.jsp?boardid=24&threadid=44955

设计目标
Ø    提供一个线程池的组件,具有良好的伸缩性,当线程够用时,销毁不用线程,当线程不够用时,自动增加线程数量;
Ø    提供一个工作任务接口和工作队列,工作队列只接受实现工作任务接口的的工作,工作任务可以自由在工作队列中取放,取出执行的工作任务将从工作队列中删除。
Ø    线程池中的线程从工作队列中,自动取得工作任务,执行任务。
主要控制类和功能接口设计
线程池管理器ThreadPoolManager的功能:
Ø    管理线程池中的各个属性变量
ü    初始化最大工作线程数
ü    初始化最小工作线程数
ü    存放线程的数据结构
ü    线程池线程增长步长
ü    任务工作队列
ü    线程活动标识位
ü    工作线程 监视狗
ü    空闲秒数
Ø    提供线程池启动接口
Ø    提供线程池销毁接口

工作线程WorkThread  的功能:
ü    从工作队列中获取工作任务
ü    执行工作任务

工作队列IWorkQueue  的功能:
Ø    提供加入任务接口;
Ø    提供删除任务接口;
Ø    提供取得任务总数接口;
Ø    提供删除所有任务接口;

工作任务接口 Itask 的功能:
Ø    提供执行任务接口.

核心代码:

CODE:
package com.teksen.component.multithread;

import com.teksen.component.multithread.impl.MyTask;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.teksen.foundation.log.Logger;
import com.teksen.foundation.log.LoggerFactory;

/**
 * <p>Title: 线程池管理器</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class ThreadPoolManager {
  /* 空闲60秒 */
  public static final long DEFAULT_IDLE_TIMEOUT = 10000L;
  
  /* 空闲60秒 */
  private long IDLE_TIMEOUT = DEFAULT_IDLE_TIMEOUT;

  /* 线程池线程增长步长 */
  public static final int INCREASE_STEP = 2;

  /* 日志对象 */
  private static final Logger log = LoggerFactory.getLogger(ThreadPoolManager.class);
  
  /* 线程活动标识位 */
  private boolean active = true;
  
  /*最大线程数*/
  private int threads_max_num;

  /*最小线程数*/
  private int threads_min_num;
  
  /* 存放线程的数据结构 */
  private List pool = new ArrayList();

  /* 任务工作队列 */
  private IWorkQueue queue;
  
  /* 工作线程 监视狗 */
  private WorkThreadWatchDog dog ;


  /**
   * 线程池管理器
   * @param queue 任务队列
   * @param threads_min_num 工作线程最小数
   * @param threads_max_num 工作线程最大数
   */
  public ThreadPoolManager(int threads_min_num
                          ,int threads_max_num
                          ,IWorkQueue queue){
    this.threads_max_num = threads_max_num;
    this.threads_min_num = threads_min_num;
    this.queue = queue;
        
    log.debug(" ThreadPoolManager initalize data :");
    log.debug("  =threads_max_num :"+threads_max_num);
    log.debug("  =threads_min_num :"+threads_min_num);
    log.debug("  =queue's :"+queue.getTaskSize());
  }

  public ThreadPoolManager(int threads_min_num
          ,int threads_max_num
          ,IWorkQueue queue,long IDLE_TIMEOUT){
	  this(threads_min_num,threads_max_num,queue);
	  if(IDLE_TIMEOUT>1000){
		  this.IDLE_TIMEOUT = IDLE_TIMEOUT;
	  }
  }
  /**
   * 启动
   */
  public void startPool(){
    dog = new WorkThreadWatchDog();
    dog.setDaemon(true);
    dog.start();
	log.debug(" ThreadPoolManager is startPool .");
  }

  /**
   * 停止
   */
  public void stopPool(){
    log.debug(" ThreadPoolManager is stopPool.");
    this.active = false;
    
    if(!dog.isInterrupted()){
        try{
            log.debug(dog.getName() + "  ===>interrupt");
            dog.interrupt();
            synchronized(dog){
                log.debug(dog.getName() + "  ===>notifyAll");
                dog.notifyAll();
            }
        }
	    catch(Throwable ex){
	        log.error(dog.getName() + " interrupt that is failure .",ex);
	    }

        try{
          log.debug(dog.getName() + "  ===>join");
          dog.join();
        }
        catch(Throwable ex){
          log.error(dog.getName() + " join:"+ex);
        }
    }// end if
    
    
 
    /* 删除所有活动线程 */
    Iterator iterator = null;
    WorkThread tempThread = null;
    
    log.debug("destroy active threads ... starting...");
    iterator = pool.iterator();
    while(iterator.hasNext()){
    	tempThread = (WorkThread)iterator.next();
        if(tempThread != null ){
        
          if(tempThread.isAlive() 
        		  && (!tempThread.isMyinterrupted() 
        				  || !tempThread.isInterrupted() ) ){
        	  
            synchronized(tempThread){
              tempThread.notifyAll();
              log.debug(tempThread.getName() + "  ===>notifyAll");
            }//end syn

            try{
                log.debug(tempThread.getName() + "  ===>interrupt");
                tempThread.interrupt();
            }catch(Throwable ex){
                log.error(tempThread.getName() +  " interrupt that is failure .",ex);
            }
            
            try{
              log.debug(tempThread.getName() + "  ===>join");
              tempThread.join();
            }catch(Throwable ex){
                log.error(tempThread.getName() +  " join that is failure .",ex);
            }
          }
          
        }//end if
    }//end while
    log.debug("destroy all active threads ... is ok ...");
    
    

    pool.clear();
    pool = null;
    dog = null;
    tempThread = null;
    
    log.debug("clear pool... is ok ...");
    log.debug("stopPool ... end ok ... ");
  }
  
/*
 * 工作线程狗,监视工作线程
 */
class WorkThreadWatchDog extends Thread{
  public WorkThreadWatchDog(){
    super("WorkThread_WatchDog");
  }
  
  public void run(){
    WorkThread temp = null;

    //phase 1 ==================================================================
    log.debug(" WorkThreadWatchDog is run . ");
    
    /* 开启最小线程数 */
    for(int i=0; i < threads_min_num ;i++){
      temp = new WorkThread("ThreadPool_"+(i+1));
      temp.start();
      pool.add(temp);
      
      log.debug(temp.getName() + " is start [NEW]. ");
    }// end for
    temp = null;

    
    
    //phase 2 ==================================================================
    /* 线程总数,初始化为最小值 */
    int poolsize = threads_min_num;
    
    /* 任务数 */
    int tasksize = 0;
    
    /* 线程池走查器 */
    Iterator poolIterator = null;
    
    /* 循环执行操作 */
    for(long times=1; active && !this.isInterrupted(); times++){
		/* 让狗睡眠指定时间 ========================*/
  	  synchronized(this){
  	    try{
  	      log.debug(this.getName()+" wait a moment ... ");
  	      this.wait(IDLE_TIMEOUT);
  	    }
  	    catch(Throwable ex){
  	      log.error(this.getName()+" wait:"+ex);
  	      break;
  	    }
  	  }
    	

      /* 任务总数 */
      tasksize = queue.getTaskSize();
      log.debug("===========================Dog watch operate [New]:"+times);
      log.debug(this.getName()+": tasksize = "+tasksize);
      log.debug(this.getName()+": poolsize = "+poolsize);
      
      /* tasksize < (poolsize*2), 让狗按指定时间睡眠,并且收缩池 */
      if(tasksize <= (poolsize*2) && poolsize > threads_min_num ){
        
        /* 没有任务时,按步长缩减线程 ------------------------------------ */
          log.debug(this.getName()+ " : tasksize <= (poolsize*2) and shrink thread pool ... ");
          
          /* 按步长程数 */
          poolIterator = pool.iterator();
          
          /* 线程关闭动作 */
          for(int i=0; (i<INCREASE_STEP) 
          			&& (poolsize > threads_min_num) 
          			&& poolIterator.hasNext();i++){
        	  
            /* workThread 实例的不同线程 */
        	temp = (WorkThread)poolIterator.next();
        	
            if(temp != null){              
              /* 关闭工作线程的睡眠标识为TRUE的线程 */
              if((temp.isSleeped  || !temp.isMyinterrupted()) && !temp.isInterrupted()){
                --poolsize;
                temp.interrupt();
                synchronized(temp){
                  temp.notifyAll();
                }
                log.debug(temp.getName()+ " is shrinked.");                
              }
            }// end if
          }//end for==========================================
          temp = null;

      }//收缩动作结束


      /* 
       * 有任务----------1
       */      
        /* 当任务总数大于线程总数的两倍时,按步长增加线程 */
        if(tasksize > (poolsize*2) && poolsize<threads_max_num){
          log.debug(this.getName()+" is increase threads... ");
          
          /* 按步长程数 */
          for(int i=0; i<INCREASE_STEP && poolsize<=threads_max_num ;i++){
            ++poolsize;
            temp = new WorkThread("ThreadPool_"+poolsize);
            temp.start();
            pool.add(temp);
            
            log.debug(temp.getName() + " is start [NEW]. ");            
          }// end for       
          temp = null;            
        }//end if 结束伸动作.
        
        /* 唤醒所有钝化线程执行任务 ================*/
        log.debug(this.getName()+ " wake up all passivated threads ... ");
        poolIterator = pool.iterator();
        while(poolIterator != null &&poolIterator.hasNext()){
      	  temp = (WorkThread)poolIterator.next();
          if(temp != null ){
            synchronized(temp){
              temp.notifyAll();
            }
            log.debug(this.getName()+ " Wake up the thread ["+temp.getName()+"]");
          }     
        }//end while
        temp = null;
        
          
    }//end while    
    
    log.debug(this.getName() + " is over ... ");
  }//end run
  
  
  
}
  
/**
 * 工作线程
 */
class WorkThread extends Thread{
    private boolean isSleeped = false;
    private boolean isMyinterrupted = false;
    
    public boolean isMyinterrupted(){
      return isMyinterrupted;
    }
    
    public WorkThread(String name){
      super(name);
    }
    
    public void run(){
      ITask task = null;
      String threadName="["+this.getName()+"]";
      log.debug("this.currentThread:"+Thread.currentThread().getName());
      
      /* 活动标志位 */
      while(active && !isMyinterrupted && !isInterrupted()){     
        /* 获取任务 ,如果没有任务则等待 */
        while((task = queue.getTask())==null){          
          synchronized(this){
            try {
              log.debug(threadName + " wait ... ");
              this.isSleeped = true;
              wait();
              this.isSleeped = false;
              log.debug(threadName + " is waked up  ... ");
            } catch (Throwable ex) {
              log.error(threadName  + " wait that is failure. ",ex);
              isMyinterrupted = true;
              this.isSleeped = false;
              break;
            }
          }
        }//end while----------

       if(this.isInterrupted() || isMyinterrupted ){
        log.debug(threadName + " is interrupted, break while cycle.[1]");
        break;
       }

        /* 执行任务 */
        try{
          if(task != null){
            log.debug(threadName + " excute owner task ... ");
            task.executeTask();
          }
        }catch(Throwable ex){
          log.error(threadName +  " executeTask:"+ex);
        }
      }//end while
      
      log.debug(threadName + " the thread is already stoped ... ");
    }
}

  public static void main(String[] args){
    IWorkQueue queue = new WorkQueue();
    ThreadPoolManager tm = new ThreadPoolManager(3,6,queue);
    tm.startPool();
    
    for(int i=0; i<20 ; i++){
      queue.addTask(new MyTask(i));
    }
    
    try{
      Thread.sleep(15000);
      tm.stopPool();
    }
    catch(Throwable ex){
      log.error("sleep:"+ex);
    }    
  }  
}

处理结果:

DEBUG com.teksen.component.multithread.ThreadPoolManager  -  ThreadPoolManager initalize data :
DEBUG com.teksen.component.multithread.ThreadPoolManager  -   =threads_max_num :6
DEBUG com.teksen.component.multithread.ThreadPoolManager  -   =threads_min_num :3
DEBUG com.teksen.component.multithread.ThreadPoolManager  -   =queue's :0
DEBUG com.teksen.component.multithread.ThreadPoolManager  -  ThreadPoolManager is startPool .
DEBUG com.teksen.component.multithread.ThreadPoolManager  -  WorkThreadWatchDog is run . 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_1 is start [NEW]. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - this.currentThread:ThreadPool_1
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] wait ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_2 is start [NEW]. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_3 is start [NEW]. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog wait a moment ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - this.currentThread:ThreadPool_2
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] wait ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - this.currentThread:ThreadPool_3
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] wait ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ===========================Dog watch operate [New]:1
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog: tasksize = 20
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog: poolsize = 3
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog is increase threads... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_4 is start [NEW]. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - this.currentThread:ThreadPool_4
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_5 is start [NEW]. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - this.currentThread:ThreadPool_5
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] excute owner task ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog wake up all passivated threads ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] excute owner task ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog Wake up the thread [ThreadPool_1]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] is waked up  ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] excute owner task ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] is waked up  ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] excute owner task ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog Wake up the thread [ThreadPool_2]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] is waked up  ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] excute owner task ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog Wake up the thread [ThreadPool_3]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog Wake up the thread [ThreadPool_4]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog Wake up the thread [ThreadPool_5]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog wait a moment ... 
MyTask[0] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] excute owner task ... 
MyTask[1] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] excute owner task ... 
MyTask[2] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] excute owner task ... 
MyTask[3] executeTask. 
MyTask[4] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] excute owner task ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] excute owner task ... 
MyTask[6] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] excute owner task ... 
MyTask[5] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] excute owner task ... 
MyTask[7] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] excute owner task ... 
MyTask[8] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] excute owner task ... 
MyTask[9] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] excute owner task ... 
MyTask[10] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] excute owner task ... 
MyTask[11] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] excute owner task ... 
MyTask[12] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] excute owner task ... 
MyTask[13] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] excute owner task ... 
MyTask[14] executeTask. 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] excute owner task ... 
MyTask[15] executeTask. 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] wait ... 
MyTask[16] executeTask. 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] wait ... 
MyTask[17] executeTask. 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] wait ... 
MyTask[19] executeTask. 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] wait ... 
MyTask[18] executeTask. 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] wait ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  -  ThreadPoolManager is stopPool.
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog  ===>interrupt
ERROR com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDogwait:java.lang.InterruptedException
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog is over ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog  ===>notifyAll
DEBUG com.teksen.component.multithread.ThreadPoolManager  - WorkThread_WatchDog  ===>join
DEBUG com.teksen.component.multithread.ThreadPoolManager  - destroy active threads ... starting...
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_1  ===>notifyAll
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_1  ===>interrupt
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_1  ===>join
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] is waked up  ... 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] wait ... 
ERROR com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] wait that is failure. 
java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:429)
    at com.teksen.component.multithread.ThreadPoolManager$WorkThread.run(ThreadPoolManager.java:330)
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] is interrupted, break while cycle.[1]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_1] the thread is already stoped ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_2  ===>notifyAll
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_2  ===>interrupt
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] is waked up  ... 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] wait ... 
ERROR com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] wait that is failure. 
java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:429)
    at com.teksen.component.multithread.ThreadPoolManager$WorkThread.run(ThreadPoolManager.java:330)
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] is interrupted, break while cycle.[1]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_2] the thread is already stoped ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_2  ===>join
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_3  ===>notifyAll
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_3  ===>interrupt
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_3  ===>join
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] is waked up  ... 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] wait ... 
ERROR com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] wait that is failure. 
java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:429)
    at com.teksen.component.multithread.ThreadPoolManager$WorkThread.run(ThreadPoolManager.java:330)
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] is interrupted, break while cycle.[1]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_3] the thread is already stoped ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_4  ===>notifyAll
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_4  ===>interrupt
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_4  ===>join
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] is waked up  ... 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] wait ... 
ERROR com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] wait that is failure. 
java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:429)
    at com.teksen.component.multithread.ThreadPoolManager$WorkThread.run(ThreadPoolManager.java:330)
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] is interrupted, break while cycle.[1]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_4] the thread is already stoped ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_5  ===>notifyAll
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_5  ===>interrupt
DEBUG com.teksen.component.multithread.ThreadPoolManager  - ThreadPool_5  ===>join
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] is waked up  ... 
DEBUG com.teksen.component.multithread.WorkQueue  - No task in queue !
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] wait ... 
ERROR com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] wait that is failure. 
java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:429)
    at com.teksen.component.multithread.ThreadPoolManager$WorkThread.run(ThreadPoolManager.java:330)
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] is interrupted, break while cycle.[1]
DEBUG com.teksen.component.multithread.ThreadPoolManager  - [ThreadPool_5] the thread is already stoped ... 
DEBUG com.teksen.component.multithread.ThreadPoolManager  - destroy all active threads ... is ok ...
DEBUG com.teksen.component.multithread.ThreadPoolManager  - clear pool... is ok ...
DEBUG com.teksen.component.multithread.ThreadPoolManager  - stopPool ... end ok ... 

阅读书源校验工具v2.0:从原理到实战优化 本文深入解析阅读书源校验工具v2.0的核心升级与优化策略,包括多线程控制机制、去重算法和智能重试策略的改进。通过实战案例和数据对比,展示v2.0在校验速度、内存占用和准确率上的显著提升,帮助用户高效识别和管理优质书源。 阅读详情

相关推荐

echarts实现折线图上下限区域展示

效果图: 画这种区域中主要是利用了series的两个属性: 思路:上下限都画上区域,然后折线利用图形透明度隐藏,给上区域加上颜色,给下区域加上白色(echarts图背景是啥色,就加啥色) lineStyle: { opacity: 0 }, // 图形透明度。支持从 0 到 1 的数字,为 0 时不绘制该图形 areaStyle: { color: 'rgba(0,122,255,0.1)' }, // 填充的颜色 我的需求是最大天数、最小天数、

小太阳的博客 1万+

线程池的实现v2.0(可伸缩线程池)

对之前V1.0版本的静态线程池进行修改,添加了一个名为management_thread的管理线程,该线程会根据任务队列的任务数量动态管理线程池中的线程数量。管理线程会在每次循环中根据一定的条件增加或减少线程数量,然后休眠一段时间后继续检查。对于静态线程池,我们额外引入一个管理线程专门来管理线程池。当线程池中的线程数量不足够匹配任务队列里的任务量,就增加线程;如果线程数量超出了任务队列的任务量,就减少线程。具体可伸缩的条件由我们自己来规定,比如说待处理的任务数>正在工作的线程数*2,就增加线程;

qq_25218501的博客 655

Unity开源游戏源码精选:17个亲测可运行教学项目

Unity游戏开发中,掌握真实项目结构与工程实践远比熟记API更重要。本文围绕‘Unity开源项目’和‘游戏源码’两大核心概念,解析高质量开源资源的本质特征——结构清晰、逻辑可溯、修改即时反馈。从基础的MonoBehaviour生命周期组织,到进阶的ScriptableObject数据驱动、事件总线解耦,再到架构级的DOTS ECS设计与网络同步模式,技术价值在于将抽象原理落地为可调试、可验证、可迁移的代码范式。适用于新手建立开发直觉、中级开发者突破系统设计瓶颈,以及团队构建可维护框架。所有项目均基于Uni

weixin_31528001的博客 746

XXL-JOB v2.0.2,分布式任务调度平台

v2.0.2 Release Notes 1、底层通讯方案优化:升级较新版本xxl-rpc,由"JETTY"方案调整为"NETTY_HTTP"方案,执行器内嵌netty-http-server提供服务,调度中心复用容器端口提供服务; 2、任务告警逻辑调整,改为通过扫描失败日志方式触发。一方面精确扫描失败任务,降低扫描范围;另一方面取消内存队列,降低线程内存消耗; 3、Quartz触发线程池废弃并...

许雪里 1542

《点云进阶》专栏文章目录

点云进阶》专栏文章目录

点云侠的博客 4911

手写简易线程池

/**手写简易的线程池 * @author 胡庆安 * @version V1.0 * @Package Thread.pool * @date 2020/10/23 10:57 * @Copyright © 2010-2020 爬山虎科技(扬州)股份有限公司 */ public class HqaPool { /** * 核心线程数 */ i...

weixin_44012945的博客 133

【GlobalMapper精品教程】027:路径剖面和和视线工具的使用

路径剖面视线工具允许您使用加载的高程数据集沿用户指定的路径获取垂直剖面。要定义生成3D路径剖面所遵循的路径,只需单击鼠标左键选择路径的点,然后石键单击以结束路径。出现一个带有剖面的对话框,允许您设置视线分析或优化端点。

智慧空间实验室 2066

RaftKeeper v2.1.0版本发布,性能大幅提升!

在RaftKeeper整个请求处理链路中,创建snapshot是在主链路中进行处理的,当数据量大的时候会长时间阻塞用户请求,造成请求超时、leader切换等引起服务不可用的问题,在我们线上场景中对于6000w的数据做snapshot需要180s。一个很直观的优化思路,可以设计一个compact strings,数据采用紧凑的方式存储,在以下的设计中,采用两个连续内存空间,一个用于存储数据,一个用于存储offset,具体参考:CompactStrings实现。

京东科技开发者 435

工业视觉实战:用摄像头+AI高精度测量钢板尺寸(附深度分析)

摘要: 钢铁制造业正加速采用基于摄像头与深度学习的视觉测量技术,以取代传统人工测量,实现钢板长、宽、高(厚)的非接触、高精度在线检测。核心方案包括单目视觉(低成本但受限于变形)、双目/多目立体视觉(可精确测量变形钢板)及3D激光扫描(微米级精度)。系统精度受硬件(相机分辨率、镜头)、算法(亚像素技术)及环境稳定性共同影响,综合精度可达±0.1mm。实战中需重点解决热膨胀(需红外测温实时补偿)和钢板变形(必须采用三维方案)两大挑战,并通过工程化设计(散热、防振)确保系统可靠运行。该技术需融合光学、机械与算法,

数字人生 396

YOLO11涨点优化:知识蒸馏 | 引入FGD(Focal and Global Distillation)蒸馏,让轻量学生模型汲取大模型全局感知力

文章摘要 目标检测模型YOLO11在轻量化部署中存在"全局盲区"问题,即轻量模型感受野不足导致大尺度场景下性能下降。知识蒸馏技术FGD(Focal and Global Distillation)通过双分支机制有效解决这一问题:Focal Distillation分离前景背景特征,让学生模型聚焦关键区域;Global Distillation传递像素间关系信息,弥补全局感知缺陷。实验表明,FGD可使YOLO11轻量版mAP提升2.5%以上,且不增加推理耗时。本文详细解析了FGD原理,并给出YOLO11上的实

2601_95807009的博客 247

RaftKeeper v2.1.0 版本发布,性能大幅提升!

RaftKeeper 是一款高新能分布式共识服务,完全兼容 Zookeeper 但性能更出色,更多关于 RaftKeeer 参考Github,我们将 RaftKeeper 大规模应用到 ClickHouse 场景中,用于解决 ZooKeeper 的性能瓶颈问题,同时 RaftKeeper 也可以用于其它大数据组件比如 H...

weixin_41400622的博客 62

基于XDMA 的PCIE读写DDR

基于XDMA 的PCIE读写DDR 概述:   想实现基于FPGA的PCIe通信,查阅互联网各种转载…基本都是对PCIe的描述,所以想写一下基于XDMA的PCIe通信的实现(PCIe结构仅做简单的描述(笔记),了解详细结构移至互联网)。 实现功能:PC通过PCIE读写DDR,同时用户通过逻辑代码可以读取被写入DDR内的数据(我是通过VIO实现DDR任意地址,任意数据大小的读取。)。 实践实践!!! 说明: 参考文档: PCI Express Base Specification Revision 3.0 P

Crazzy_M的博客 1万+

笨笨图片批量抓取下载 V0.2 beta

 前言      从【笨笨图片批量抓取下载 V0.2 beta】到【笨笨图片批量下载器 V0.3 beta】时间将近2个月,不是说这个升级版本开发了这么久,实在是懒,呵呵: )再加有时候工作忙、学习,多的时间就不愿意动了,现在都感觉辜负了上一版N多朋友的支持了,不过这将近一个星期时间我按计划完成了这个小软件版的升级开发,并且依然和上两个版本一样保持源代码开源,文章最后有下载地址,以下是这个

神经网络爱好者 1099

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

xxl子任务_XXLJOB v2.0.2,分布式任务调度平台

v2.0.2 Release Notes1、底层通讯方案优化:升级较新版本xxl-rpc,由"JETTY"方案调整为"NETTY_HTTP"方案,执行器内嵌netty-http-server提供服务,调度中心复用容器端口提供服务;2、任务告警逻辑调整,改为通过扫描失败日志方式触发。一方面精确扫描失败任务,降低扫描范围;另一方面取消内存队列,降低线程内存消耗;3、Quartz触发线程池废弃...

weixin_39867208的博客 179

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【Linux网络】构建UDP网络服务:从Echo到聊天室的线程池架构演进

本文介绍了使用Socket编程实现UDP通信的基本方法,重点讲解了相关函数的使用和实现步骤。主要内容包括: 关键头文件和函数介绍:包括socket()创建套接字、bind()绑定端口、recvfrom()/sendto()收发数据报等核心函数。 InetAddr类的实现:封装了IP地址和端口号的转换功能,提供网络序列与主机序列之间的转换方法。 Server_udp类的实现:展示了UDP服务器的完整实现流程,包括初始化套接字、绑定地址、接收和发送数据等核心功能。

无限进步!!! 858

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

quartz 与xxl_xxl-job v2.1.0正式发布

2019年7月7日,国内开源调度框架xxl-job发布最新v2.1.0版本,该版本在底层调度框架上移除对quartz依赖,可谓是一次非常大的版本更新。v2.1.0更新说明自研调度组件,移除quartz依赖:一方面是为了精简系统降低冗余依赖,另一方面是为了提供系统的可控度与稳定性;触发:单节点周期性触发,运行事件如delayqueue;调度:集群竞争,负载方式协同处理,锁竞争-更新触发信息-推送时间...

weixin_33677704的博客 519

[250201] isd v0.3.0 发布:全新快捷键逻辑及其他改进 | Puma 6.6.0 版本发布

- isd v0.3.0 发布:全新快捷键逻辑及其他改进 - Puma 6.6.0 版本发布

edwinjhlee的博客 1100

【Linux之旅】Linux TCP Socket 编程实战:从单连接到线程池,构建高并发服务端

上一篇我们掌握了 UDP 编程——无连接、直发直收,简单但不可靠。本篇进入 TCP Socket 编程,TCP 的核心差异在于"连接管理":三次握手建立连接、四次挥手断开连接、确认重传保证可靠。多出来的复杂度换来了**可靠的字节流传输**,这是绝大多数互联网应用(HTTP、SSH、数据库协议)选择 TCP 的原因。

2302_80243065的博客 989

用最近最少用(lru)页面调度算法处理缺页中断_XXL-JOB v2.0.2,分布式任务调度平台...

v2.0.2 Release Notes1、底层通讯方案优化:升级较新版本xxl-rpc,由"JETTY"方案调整为"NETTY_HTTP"方案,执行器内嵌netty-http-server提供服务,调度中心复用容器端口提供服务;2、任务告警逻辑调整,改为通过扫描失败日志方式触发。一方面精确扫描失败任务,降低扫描范围;另一方面取消内存队列,降低线程内存消耗;3、Quartz触发线程池废弃并替换为 ...

weixin_39798626的博客 191

Flink 2.0 解耦状态管理(Disaggregated State)ForSt + 异步 State API V2 + SQL Async-State 上手与调优

Flink 2.0引入的解耦状态管理解决了大状态作业面临的容量限制、稳定性问题和恢复速度等痛点。其核心由ForSt State Backend、State API V2和SQL异步算子三部分组成,支持将状态存储在远端文件系统,并通过异步访问提升性能。目前该功能仍处于实验阶段,建议从SQL作业开始试点,逐步迁移DataStream作业,并关注checkpoint时长、恢复时间和性能抖动等指标。对于状态较小的场景,本地状态可能仍是更优选择。落地时需制定明确的试点策略和回滚方案。

hello.reader 1477

低代码后端平台搭建-v2.0

从零开始搭建低代码平台后端--2-1

lyk1184919379的博客 1299

开源项目 unveilr-v2.0.0 推荐

**主要编程语言**: TypeScript 和 JavaScript unveilr-v2.0.0 是一个小程序反编译工具,旨在帮助开发者检测和提升小程序的安全性。该项目使用 TypeScript 和 JavaScript 编写,提供了丰富的功能,包括代码审查、漏洞扫描等,以确保小程序的安全运行。 ## 2. 项目的核心功能 - **小程序反编译**: 支持解析最新版的小程序包(如 APP...

gitblog_07390的博客 539

为什么头部音视频中台集体延迟接入Seedance 2.0?——一份被内部封存的Node.js运行时对比白皮书

揭秘音视频中台延迟接入原因,提供Seedance 2.0 SDK 在 Node.js 环境的部署 对比评测报告。覆盖主流运行时(Node.js 18/20/22)性能、内存占用与SDK兼容性实测,揭示V8优化瓶颈与Polyfill风险。适用于中台架构选型与升级决策,值得收藏。

ProcePerch的博客 319

用最近最少用(lru)页面调度算法处理缺页中断_XXL-JOB v2.0.2,分布式任务调度平台 | 多项特性优化更新...

v2.0.2 Release Notes1、底层通讯方案优化:升级较新版本xxl-rpc,由"JETTY"方案调整为"NETTY_HTTP"方案,执行器内嵌netty-http-server提供服务,调度中心复用容器端口提供服务;2、任务告警逻辑调整,改为通过扫描失败日志方式触发。一方面精确扫描失败任务,降低扫描范围;另一方面取消内存队列,降低线程内存消耗;3、Quartz触发线程池废弃并替换为 ...

weixin_39681644的博客 393
上一篇: 人在江湖飘
下一篇: 社会生活中的著名法则(ZT)
mdwolf
博客等级 码龄25年 7粉丝 31原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址