public class DiscardWithCancelPolicy extends Object implements RejectedExecutionHandler
Use this policy for efficiently discarding rejected tasks. Unlike CallerRunsPolicy
, this policy maintains the order of tasks in the task
queue. Unlike DiscardOldestPolicy
and DiscardPolicy
, which
ultimately call Future.get()
, threads do not block waiting for a
timeout.
Constructor and Description |
---|
DiscardWithCancelPolicy() |
Modifier and Type | Method and Description |
---|---|
void |
rejectedExecution(Runnable runnable,
ThreadPoolExecutor threadPoolExecutor)
Rejects execution of the
Runnable task by canceling it
immediately. |
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolExecutor)
Runnable
task by canceling it
immediately.
Important: The task can only be canceled if it is a
subtype of Future
.
rejectedExecution
in interface RejectedExecutionHandler
runnable
- the taskthreadPoolExecutor
- the executorRejectedExecutionHandler.rejectedExecution(
Runnable, java.util.concurrent.ThreadPoolExecutor)