Class ExecutorTools


  • public class ExecutorTools
    extends java.lang.Object
    Utility methods for working with executors.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static com.sedmelluq.lava.common.tools.ExecutorTools.CompletedVoidFuture COMPLETED_VOID
      A completed Future<Void> instance.
    • Constructor Summary

      Constructors 
      Constructor Description
      ExecutorTools()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.concurrent.ThreadPoolExecutor createEagerlyScalingExecutor​(int coreSize, int maximumSize, long timeout, int queueCapacity, java.util.concurrent.ThreadFactory threadFactory)
      Creates an executor which will use the queue only when maximum number of threads has been reached.
      static void shutdownExecutor​(java.util.concurrent.ExecutorService executorService, java.lang.String description)
      Shut down an executor and log the shutdown result.
      • Methods inherited from class java.lang.Object

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

      • COMPLETED_VOID

        public static final com.sedmelluq.lava.common.tools.ExecutorTools.CompletedVoidFuture COMPLETED_VOID
        A completed Future<Void> instance.
    • Constructor Detail

      • ExecutorTools

        public ExecutorTools()
    • Method Detail

      • shutdownExecutor

        public static void shutdownExecutor​(java.util.concurrent.ExecutorService executorService,
                                            java.lang.String description)
        Shut down an executor and log the shutdown result. The executor is given a fixed amount of time to shut down, if it does not manage to do it in that time, then this method just returns.
        Parameters:
        executorService - Executor service to shut down
        description - Description of the service to use for logging
      • createEagerlyScalingExecutor

        public static java.util.concurrent.ThreadPoolExecutor createEagerlyScalingExecutor​(int coreSize,
                                                                                           int maximumSize,
                                                                                           long timeout,
                                                                                           int queueCapacity,
                                                                                           java.util.concurrent.ThreadFactory threadFactory)
        Creates an executor which will use the queue only when maximum number of threads has been reached. The core pool size here only means the number of threads that are always alive, it is no longer used to check whether a new thread should start or not. The maximum size is otherwise pointless unless you have a bounded queue, which in turn would cause tasks to be rejected if it is too small.
        Parameters:
        coreSize - Number of threads that are always alive
        maximumSize - The maximum number of threads in the pool
        timeout - Non-core thread timeout in milliseconds
        threadFactory - Thread factory to create pool threads with
        Returns:
        An eagerly scaling thread pool executor