Summary of improper use of thread pool

1. Unreasonable rejection policy settings lead to infinite blocking and waiting of threads

insert image description here
The rejection policy is set to discard, if you go to get again, it will always be blocked

2. Deadlock caused by nested use of thread pool

The threads in the thread pool use the threads in the thread pool, and the parent and child threads wait for each other:

Assume that the maximum number of executorService threads is 10.
When 10 requests arrive at the same time, the thread pool is full, and the child task request is forced to enter the blocking queue,
but the completion of the parent task depends on the child task. At this time, because the child task cannot get the thread, the parent The task cannot be completed.
The main thread executes join() and enters the blocking state, because the result can never be obtained and can never be recovered, causing service failure

Thread pool isolation must be performed when calling in parallel

Guess you like

Origin blog.csdn.net/itguangit/article/details/128017788