Class ThreadPoolExecutorProvider

    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadPoolExecutorProvider​(java.lang.String name)
      Create a new instance of the thread pool executor provider.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.concurrent.ThreadPoolExecutor createExecutor​(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.ThreadFactory threadFactory, java.util.concurrent.RejectedExecutionHandler handler)
      Creates a new ThreadPoolExecutor with the given initial parameters.
      protected java.util.concurrent.ThreadPoolExecutor createExecutor​(int corePoolSize, java.util.concurrent.ThreadFactory threadFactory, java.util.concurrent.RejectedExecutionHandler handler)
      Create a new instance of the thread pool executor that should be provided by the AbstractThreadPoolProvider.getExecutor() method.
      void dispose​(java.util.concurrent.ExecutorService executorService)
      Invoked when Jersey runtime no longer requires use of the provided executor service.
      java.util.concurrent.ExecutorService getExecutorService()
      Get an executor service to be used by Jersey client or server runtime to execute specific tasks.
      protected long getKeepAliveTime()
      Get the thread keep-alive time (in seconds).
      protected int getMaximumPoolSize()
      Get the maximum number of threads to allow in the thread pool.
      protected java.util.concurrent.BlockingQueue<java.lang.Runnable> getWorkQueue()
      Get the work queue for the provisioned thread pool executor.
      void preDestroy()
      Container pre-destroy handler method.
      • Methods inherited from class java.lang.Object

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

      • CACHED_POOL_KEEP_ALIVE_DEFAULT_TIMEOUT

        private static final long CACHED_POOL_KEEP_ALIVE_DEFAULT_TIMEOUT
        See Also:
        Constant Field Values
    • Constructor Detail

      • ThreadPoolExecutorProvider

        public ThreadPoolExecutorProvider​(java.lang.String name)
        Create a new instance of the thread pool executor provider.
        Parameters:
        name - provider name. The name will be used to name the threads created & used by the provisioned thread pool executor.
    • Method Detail

      • getExecutorService

        public java.util.concurrent.ExecutorService getExecutorService()
        Description copied from interface: ExecutorServiceProvider
        Get an executor service to be used by Jersey client or server runtime to execute specific tasks.

        This method is usually invoked just once at either Jersey client or server application runtime initialization, it may however be invoked multiple times. Once the instance of the provided executor service is not needed anymore by Jersey application runtime, it will be disposed. This typically happens in one of the following situations:

        • Jersey client instance is closed (client runtime is shut down).
        • Jersey container running a server-side Jersey application is shut down.
        • Jersey server-side application is un-deployed.
        Specified by:
        getExecutorService in interface ExecutorServiceProvider
        Returns:
        an executor service. Must not return null.
      • createExecutor

        protected java.util.concurrent.ThreadPoolExecutor createExecutor​(int corePoolSize,
                                                                         int maximumPoolSize,
                                                                         long keepAliveTime,
                                                                         java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue,
                                                                         java.util.concurrent.ThreadFactory threadFactory,
                                                                         java.util.concurrent.RejectedExecutionHandler handler)
        Creates a new ThreadPoolExecutor with the given initial parameters.
        Parameters:
        corePoolSize - the number of threads to keep in the thread pool, even if they are idle.
        maximumPoolSize - the maximum number of threads to allow in the thread pool.
        keepAliveTime - when the number of threads is greater than the core, this is the maximum time (in seconds) that excess idle threads will wait for new tasks before terminating.
        workQueue - the queue to use for holding tasks before they are executed. This queue will hold only the Runnable tasks submitted by the execute method.
        threadFactory - the factory to use when the executor creates a new thread.
        handler - the handler to use when execution is blocked because the thread bounds and queue capacities are reached.
        Returns:
        new configured thread pool instance.
        Throws:
        java.lang.IllegalArgumentException - if one of the following holds:
        corePoolSize < 0
        keepAliveTime < 0
        maximumPoolSize <= 0
        maximumPoolSize < corePoolSize
        java.lang.NullPointerException - if workQueue or threadFactory or handler is null.
      • getKeepAliveTime

        protected long getKeepAliveTime()
        Get the thread keep-alive time (in seconds).

        When the number of threads in the provisioned thread pool is greater than the core, this is the maximum time (in seconds) that excess idle threads will wait for new tasks before terminating.

        The value from this method is passed as one of the input parameters in a call to the createExecutor(int, int, long, java.util.concurrent.BlockingQueue, java.util.concurrent.ThreadFactory, java.util.concurrent.RejectedExecutionHandler) method.

        The method can be overridden to customize the thread keep-alive time in the provisioned thread pool executor. If not customized, the method defaults to:

        • 60L in case the maximum pool size is equal to Integer.MAX_VALUE
        • 0L in case the maximum pool size is lower than java.lang.Integer#MAX_VALUE
        The default value computation closely corresponds to the thread pool executor configurations used in Executors.newCachedThreadPool() and Executors.newFixedThreadPool(int) methods.

        Returns:
        thread keep-alive time (in seconds) for the provisioned thread pool executor.
      • getWorkQueue

        protected java.util.concurrent.BlockingQueue<java.lang.Runnable> getWorkQueue()
        Get the work queue for the provisioned thread pool executor.

        The work queue is used to hold the tasks before they are executed by the provisioned thread pool executor. The queue will hold only the Runnable tasks submitted by the ThreadPoolExecutor.execute(java.lang.Runnable) method.

        The value from this method is passed as one of the input parameters in a call to the createExecutor(int, int, long, java.util.concurrent.BlockingQueue, java.util.concurrent.ThreadFactory, java.util.concurrent.RejectedExecutionHandler) method.

        The method can be overridden to customize the work queue used by the provisioned thread pool executor. If not customized, the method defaults to:

        • SynchronousQueue in case the maximum pool size is equal to Integer.MAX_VALUE
        • LinkedBlockingQueue in case the maximum pool size is lower than java.lang.Integer#MAX_VALUE
        The default value computation closely corresponds to the thread pool executor configurations used in Executors.newCachedThreadPool() and Executors.newFixedThreadPool(int) methods.

        Returns:
        work queue for the provisioned thread pool executor.
      • dispose

        public void dispose​(java.util.concurrent.ExecutorService executorService)
        Description copied from interface: ExecutorServiceProvider
        Invoked when Jersey runtime no longer requires use of the provided executor service.
        Specified by:
        dispose in interface ExecutorServiceProvider
        Parameters:
        executorService - executor service to be disposed.
      • preDestroy

        @PreDestroy
        public void preDestroy()
        Container pre-destroy handler method.

        Invoking the method closes this provider.