Class RunWhenTasksFinishedOnRejectedHandler
- java.lang.Object
-
- com.github.javinator9889.threading.pools.rejectedhandlers.RunWhenTasksFinishedOnRejectedHandler
-
- All Implemented Interfaces:
java.util.concurrent.RejectedExecutionHandler
public class RunWhenTasksFinishedOnRejectedHandler extends java.lang.Object implements java.util.concurrent.RejectedExecutionHandlerThis handler waits until all running threads and pending ones are executed, then runs the rejectedRunnableon theThreadsPoolingthread.There is a definition available at
ThreadsPooling.WAIT_SHUTDOWN_RUN_TASK_ON_REJECTED_HANDLERthat uses a defaulttimeoutof100 ms.. You can use yours with your custom implementation by calling theRunWhenTasksFinishedOnRejectedHandler(long, TimeUnit)constructor with your custom values.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateRunWhenTasksFinishedOnRejectedHandler()Private constructor for not allowing class instantiation with no args.RunWhenTasksFinishedOnRejectedHandler(long timeout, java.util.concurrent.TimeUnit timeUnit)Generates a new handler by using the custom timeout provided.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidrejectedExecution(java.lang.Runnable thread, java.util.concurrent.ThreadPoolExecutor executor)Method that may be invoked by aThreadPoolExecutorwhenexecutecannot accept a task.
-
-
-
Constructor Detail
-
RunWhenTasksFinishedOnRejectedHandler
private RunWhenTasksFinishedOnRejectedHandler()
Private constructor for not allowing class instantiation with no args.
-
RunWhenTasksFinishedOnRejectedHandler
public RunWhenTasksFinishedOnRejectedHandler(long timeout, @NotNull java.util.concurrent.TimeUnit timeUnit)Generates a new handler by using the custom timeout provided.- Parameters:
timeout- timeout value - must be higher than zero.timeUnit- time unit for the timeout - cannot benull.
-
-
Method Detail
-
rejectedExecution
public void rejectedExecution(java.lang.Runnable thread, java.util.concurrent.ThreadPoolExecutor executor)Method that may be invoked by aThreadPoolExecutorwhenexecutecannot accept a task. This may occur when no more threads or queue slots are available because their bounds would be exceeded, or upon shutdown of the Executor.In the absence of other alternatives, the method may throw an unchecked
RejectedExecutionException, which will be propagated to the caller ofexecute.- Specified by:
rejectedExecutionin interfacejava.util.concurrent.RejectedExecutionHandler- Parameters:
thread- the runnable task requested to be executedexecutor- the executor attempting to execute this task
-
-