Class 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 rejected Runnable on the ThreadsPooling thread.

    There is a definition available at ThreadsPooling.WAIT_SHUTDOWN_RUN_TASK_ON_REJECTED_HANDLER that uses a default timeout of 100 ms.. You can use yours with your custom implementation by calling the RunWhenTasksFinishedOnRejectedHandler(long, TimeUnit) constructor with your custom values.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long mTimeout  
      private java.util.concurrent.TimeUnit mTimeUnit  
    • 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 a ThreadPoolExecutor when execute cannot accept a task.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mTimeout

        private long mTimeout
      • mTimeUnit

        private java.util.concurrent.TimeUnit mTimeUnit
    • 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 be null.
    • Method Detail

      • rejectedExecution

        public void rejectedExecution​(java.lang.Runnable thread,
                                      java.util.concurrent.ThreadPoolExecutor executor)
        Method that may be invoked by a ThreadPoolExecutor when execute 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 of execute.

        Specified by:
        rejectedExecution in interface java.util.concurrent.RejectedExecutionHandler
        Parameters:
        thread - the runnable task requested to be executed
        executor - the executor attempting to execute this task