The method is simple memory thread pool

 

  If there is a factory, the factory which has 10 workers, each worker can only do one task at the same time.

  So as long as when 10 workers in the workers are free to the task assigned to idle workers do;

  When 10 Shi workers have a task to do, if it is to the task, put the task waiting;

  If the number of new job growth is much faster than the speed of the workers to do the task, then the time plant supervisor might want to remedial measures, such as re-recruit 4 temporary workers who come in;

  Then the task will also be allocated to these 4 temporary workers who do;

  If you said 14 workers to do the task speed is not enough, then plant manager may have to consider not taking any new tasks or to abandon some of the previous task.

  When this 14 Shi was among idle workers, and the new tasks and relatively slow growth rate, plant manager might consider quitting 4 temporary workers, just to keep the original 10 workers, after all, is to make extra money workers of.

 

  In this example corePoolSize is 10 , and maximumPoolSize is 14 ( 10 + 4 ).

  That corePoolSize is the thread pool size, maximumPoolSize in my opinion is a remedy thread pool, that a remedy when a sudden large amount of tasks.

 

 

  • If the current number of threads in the thread pool is less than corePoolSize , then each to a task, it will create a thread to perform this task;
  • If the current number of threads in the thread pool > = corePoolSize , then each to a task, will try to add it to the task queue buffer which, if added successfully, the task will be idle threads waiting to execute it out; if the addition failed ( in general the task buffer queue is full), it will try to create a new thread to perform this task;
  • If the current number of threads in the thread pool reaches maximumPoolSize , then come back task, the task will take to refuse treatment strategy;
  • If the number of threads in the pool is greater than corePoolSize , if the idle time exceeds a thread keepAliveTime , the thread will be stopped until the number of threads in the pool is not larger than corePoolSize ; if allowed to pool the core thread disposed survival time, then the core cell the thread is idle for more than keepAliveTime , the thread will be terminated.

Guess you like

Origin www.cnblogs.com/muouren/p/11706528.html