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.RejectedExecutionHandler
This handler waits until all running threads and pending ones are executed, then runs the rejectedRunnable
on theThreadsPooling
thread.There is a definition available at
ThreadsPooling.WAIT_SHUTDOWN_RUN_TASK_ON_REJECTED_HANDLER
that uses a defaulttimeout
of100 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 private
RunWhenTasksFinishedOnRejectedHandler()
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 void
rejectedExecution(java.lang.Runnable thread, java.util.concurrent.ThreadPoolExecutor executor)
Method that may be invoked by aThreadPoolExecutor
whenexecute
cannot 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 aThreadPoolExecutor
whenexecute
cannot 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:
rejectedExecution
in interfacejava.util.concurrent.RejectedExecutionHandler
- Parameters:
thread
- the runnable task requested to be executedexecutor
- the executor attempting to execute this task
-
-