Study notes-java thread pool ThreadPoolExecutor

There are 10 pits in the toilet of a tourist attraction, and it just happened that ten people stood full

----------

Number of core threads corePoolSize=10

 

These 10 people have not yet finished, and another tour group has another 30 people. They are very disciplined and line up outside the toilet.

When there were 20 people in the queue, the 21st person became impatient, and thought that when it was my turn, they were all suffocated, so there were only 20 people in the team.

----------....................

Task queue capacity queueCapacity=20

 

At this time, a kind-hearted local came and told the extra people that I have a few secret toilets here. They are only used when the number of people in the queue is> 20. You can solve them there, but there are only 9 secret toilets. , The rest one can do it by yourself

----------....................*********

Maximum number of threads maxPoolSize=10+9=19

 

The last person has 4 options (rejectedExecutionHandler):

1. The toilet is no longer available, take out your mobile phone and post everywhere: a certain scenic spot does not even let people use the toilet (abortPolicy throws abnormalities during operation)

2. Solve it outside the toilet (CallerRunsPolicy is executed by the main thread)

3. Hold it! (DiscardPolicy ignores)

4. The person who kicked out the front of the queue has been holding back for so long anyway, and it will be okay if you wait (DiscardOldestPolicy)

Guess you like

Origin blog.csdn.net/u012452555/article/details/81304208