Class AbstractThreadPool

    • Constructor Detail

    • Method Detail

      • startWorker

        protected void startWorker​(AbstractThreadPool.Worker worker)
        must hold statelock while calling this method.
        Parameters:
        worker -
      • getConfig

        public ThreadPoolConfig getConfig()
        Returns:
        the thread pool configuration
      • getSize

        public final int getSize()
        Returns:
        the number of allocated threads in the thread pool
      • poisonAll

        protected void poisonAll()
      • validateNewPoolSize

        protected void validateNewPoolSize​(int corePoolsize,
                                           int maxPoolSize)
      • beforeExecute

        protected void beforeExecute​(AbstractThreadPool.Worker worker,
                                     Thread t,
                                     Runnable r)
        Method invoked prior to executing the given Runnable in the given thread. This method is invoked by thread t that will execute task r, and may be used to re-initialize ThreadLocals, or to perform logging.

        This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke super.beforeExecute at the end of this method.

        Parameters:
        worker - the AbstractThreadPool.Worker, running the the thread t
        t - the thread that will run task r.
        r - the task that will be executed.
      • afterExecute

        protected void afterExecute​(AbstractThreadPool.Worker worker,
                                    Thread thread,
                                    Runnable r,
                                    Throwable t)
        Method invoked upon completion of execution of the given Runnable. This method is invoked by the thread that executed the task. If non-null, the Throwable is the uncaught RuntimeException or Error that caused execution to terminate abruptly.

        Note: When actions are enclosed in tasks (such as FutureTask) either explicitly or via methods such as submit, these task objects catch and maintain computational exceptions, and so they do not cause abrupt termination, and the internal exceptions are not passed to this method.

        This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke super.afterExecute at the beginning of this method.

        Parameters:
        worker - the AbstractThreadPool.Worker, running the the thread t
        thread -
        r - the runnable that has completed.
        t - the exception that caused termination, or null if execution completed normally.
      • onTaskCompletedEvent

        protected void onTaskCompletedEvent​(Runnable task)

        This method will be invoked when a the specified Runnable has completed execution.

        Parameters:
        task - the unit of work that has completed processing
      • onMaxNumberOfThreadsReached

        protected void onMaxNumberOfThreadsReached()
        Method is called by AbstractThreadPool, when maximum number of worker threads is reached and task will need to wait in task queue, until one of the threads will be able to process it.
      • onTaskQueued

        protected void onTaskQueued​(Runnable task)
        Method is called by a thread pool each time new task has been queued to a task queue.
        Parameters:
        task -
      • onTaskDequeued

        protected void onTaskDequeued​(Runnable task)
        Method is called by a thread pool each time a task has been dequeued from a task queue.
        Parameters:
        task -
      • onTaskCancelled

        protected void onTaskCancelled​(Runnable task)
        Method is called by a thread pool each time a dequeued task has been canceled instead of being processed.
        Parameters:
        task -
      • onTaskQueueOverflow

        protected void onTaskQueueOverflow()
        Method is called by a thread pool, when new task could not be added to a task queue, because task queue is full. throws RejectedExecutionException
      • getDefaultThreadFactory

        protected final ThreadFactory getDefaultThreadFactory()