Thread pool Work queue saturation policy
The Java thread pool places the submitted task first in the work queue, which is fetched from the work queue (Synchronousqueue is submitted directly by the producer to the worker thread).
Then there are two implementation strategies for the work queue: unbounded queues and bounded queues.
There is no saturation problem with unbounded queues, but the problem is that when the request continues to load heavily, the task will not join the work queue without a brain, so it is likely to cause resources such as memory to overflow or drain.
While bounded queues do not cause memory exhaustion due to high load, there is a challenge of how the new submitted task will be managed when the work queue is full, which is the problem that the thread pool work queue saturation policy solves.
There is no saturation problem with unbounded queues, but the problem is that when the request continues to load heavily, the task will not join the work queue without a brain, so it is likely to cause resources such as memory to overflow or drain.
While bounded queues do not cause memory exhaustion due to high load, there is a challenge of how the new submitted task will be managed when the work queue is full, which is the problem that the thread pool work queue saturation policy solves.
The saturation strategy is divided into: Abort policy, callerruns policy, discard policy, discardolds strategy.
When the work queue is full, the different policies are handled in the following ways:
1.Abort policy: The default policy, when a new task commits, throws an unchecked exception rejectedexecutionexception, which can be captured by the caller.
When the work queue is full, the different policies are handled in the following ways:
1.Abort policy: The default policy, when a new task commits, throws an unchecked exception rejectedexecutionexception, which can be captured by the caller.
The program throws a Rejectedexecutionexception
The program throws a Rejectedexecutionexception
Thread pool Work queue saturation policy