1. AbortPolicy: This rejection strategy directly raises a RuntimeException of RejectedExecutionexception type when rejecting a task. If the task is rejected, you can retry or give up the submission according to the business logic.
2. DiscardPolicy: New task submission Then it is discarded directly without any notification, there is a certain risk, and there is a possibility of data loss.
3. DiscardOldestPolicy: After a new task is submitted, the task with the longest survival time will be discarded, and there is also the risk of losing data.
4. CallerRunsPolicy: After a new task is submitted, the task is submitted to the thread that submitted the task, that is, whoever submits the task is responsible for the task. There are two main advantages to doing this.
First, newly submitted tasks will not be abandoned and will not cause business losses.
Second, since whoever submits the task is responsible for the task, the route that submits the task must be responsible for the task, and it takes time to execute the task. During this period, the route that submits the task is occupied, and no new tasks are submitted, and the task submission speed changes. Slow, equivalent to negative feedback. During this period, the threads in the thread pool can also make full use of this time to perform some tasks and free up a certain amount of space, which is equivalent to giving the thread pool a certain buffer period.
Collections in Java are mainly divided into four categories:
1. List: ordered, repeatable;
2. Queue: ordered and repeatable;
3. Set: non-repeatable;
4. Map: unordered, with unique keys and non-unique values.
The above is the detailed content of What is the rejection policy for java thread pool?. For more information, please follow other related articles on the PHP Chinese website!