Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between corePoolSize and maxPoolSize in the Spring ThreadPoolTaskExecutor

I have to send out massEmails to all users of a website. I want to use a thread pool for each email that is sent out. Currently I have set the values to :

<property name="corePoolSize" value="500" /> <property name="maxPoolSize" value="1000" /> 

What is the difference between the two and will it scale. Currently I have approx. 10000 users.

like image 427
rabbit Avatar asked Dec 10 '09 05:12

rabbit


People also ask

What is corePoolSize and maxPoolSize?

Starting thread pool size is 1, core pool size is 5, max pool size is 10 and the queue is 100. As requests come in, threads will be created up to 5 and then tasks will be added to the queue until it reaches 100. When the queue is full new threads will be created up to maxPoolSize .

What is ThreadPoolTaskExecutor in Spring?

ThreadPoolTaskExecutor is a java bean that allows for configuring a ThreadPoolExecutor in a bean style by setting up the values for the instance variables like corePoolSize, maxPoolSize, keepAliveSeconds, queueCapacity and exposing it as a Spring TaskExecutor.

What is the default queue size in ThreadPoolExecutor?

The default configuration is a core pool size of 1, with unlimited max pool size and unlimited queue capacity. This is roughly equivalent to Executors.

What is ThreadPoolExecutor?

ThreadPoolExecutor is an ExecutorService to execute each submitted task using one of possibly several pooled threads, normally configured using Executors factory methods. It also provides various utility methods to check current threads statistics and control them.


1 Answers

Here are Sun’s rules for thread creation in simple terms:

  1. If the number of threads is less than the corePoolSize, create a new Thread to run a new task.
  2. If the number of threads is equal (or greater than) the corePoolSize, put the task into the queue.
  3. If the queue is full, and the number of threads is less than the maxPoolSize, create a new thread to run tasks in.
  4. If the queue is full, and the number of threads is greater than or equal to maxPoolSize, reject the task.

Full article

Origin answer

like image 178
taynguyen Avatar answered Sep 23 '22 22:09

taynguyen