What are the different rejection policies for Java thread pools?
There are several types of rejection policies in Java thread pools.
- ThreadPoolExecutor.AbortPolicy: The default rejection policy that throws a RejectedExecutionException when a task cannot be added to the thread pool.
 - ThreadPoolExecutor.CallerRunsPolicy: When a task cannot be added to the thread pool, it will be returned to the caller for execution. This results in reduced processing capabilities of the thread pool, as the caller has to wait for the task to be completed before continuing with their own tasks.
 - ThreadPoolExecutor.DiscardPolicy: When a task cannot be added to the thread pool, it will be discarded directly without throwing any exceptions.
 - ThreadPoolExecutor.DiscardOldestPolicy: When a task cannot be added to the thread pool, the policy first attempts to remove the oldest task in the queue and then retries adding the task.
 
The thread pool’s rejection policy can be set by calling the setRejectedExecutionHandler method of ThreadPoolExecutor.