Class ThreadPools


  • public class ThreadPools
    extends Object
    • Field Detail

      • DEFAULT_TIMEOUT_MILLISECS

        public static final long DEFAULT_TIMEOUT_MILLISECS
        See Also:
        Constant Field Values
    • Method Detail

      • getServerThreadPools

        public static final ThreadPools getServerThreadPools()
      • watchCriticalScheduledTask

        public static void watchCriticalScheduledTask​(ScheduledFuture<?> future)
      • watchCriticalFixedDelay

        public static void watchCriticalFixedDelay​(AccumuloConfiguration aconf,
                                                   long intervalMillis,
                                                   Runnable runnable)
      • watchNonCriticalScheduledTask

        public static void watchNonCriticalScheduledTask​(ScheduledFuture<?> future)
      • resizePool

        public static void resizePool​(ThreadPoolExecutor pool,
                                      IntSupplier maxThreads,
                                      String poolName)
        Resize ThreadPoolExecutor based on current value of maxThreads
        Parameters:
        pool - the ThreadPoolExecutor to modify
        maxThreads - supplier of maxThreads value
        poolName - name of the thread pool
      • resizePool

        public static void resizePool​(ThreadPoolExecutor pool,
                                      AccumuloConfiguration conf,
                                      Property p)
        Resize ThreadPoolExecutor based on current value of Property p
        Parameters:
        pool - the ThreadPoolExecutor to modify
        conf - the AccumuloConfiguration
        p - the property to base the size from
      • createExecutorService

        public ThreadPoolExecutor createExecutorService​(AccumuloConfiguration conf,
                                                        Property p,
                                                        boolean emitThreadPoolMetrics)
        Create a thread pool based on a thread pool related property
        Parameters:
        conf - accumulo configuration
        p - thread pool related property
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ExecutorService impl
        Throws:
        RuntimeException - if property is not handled
      • createFixedThreadPool

        public ThreadPoolExecutor createFixedThreadPool​(int numThreads,
                                                        String name,
                                                        boolean emitThreadPoolMetrics)
        Create a named thread pool
        Parameters:
        numThreads - number of threads
        name - thread pool name
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ThreadPoolExecutor
      • createFixedThreadPool

        public ThreadPoolExecutor createFixedThreadPool​(int numThreads,
                                                        String name,
                                                        BlockingQueue<Runnable> queue,
                                                        boolean emitThreadPoolMetrics)
        Create a named thread pool
        Parameters:
        numThreads - number of threads
        name - thread pool name
        queue - queue to use for tasks
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ThreadPoolExecutor
      • createFixedThreadPool

        public ThreadPoolExecutor createFixedThreadPool​(int numThreads,
                                                        long timeOut,
                                                        TimeUnit units,
                                                        String name,
                                                        boolean emitThreadPoolMetrics)
        Create a named thread pool
        Parameters:
        numThreads - number of threads
        timeOut - core thread time out
        units - core thread time out units
        name - thread pool name
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ThreadPoolExecutor
      • createThreadPool

        public ThreadPoolExecutor createThreadPool​(int coreThreads,
                                                   int maxThreads,
                                                   long timeOut,
                                                   TimeUnit units,
                                                   String name,
                                                   boolean emitThreadPoolMetrics)
        Create a named thread pool
        Parameters:
        coreThreads - number of threads
        maxThreads - max number of threads
        timeOut - core thread time out
        units - core thread time out units
        name - thread pool name
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ThreadPoolExecutor
      • createThreadPool

        public ThreadPoolExecutor createThreadPool​(int coreThreads,
                                                   int maxThreads,
                                                   long timeOut,
                                                   TimeUnit units,
                                                   String name,
                                                   BlockingQueue<Runnable> queue,
                                                   boolean emitThreadPoolMetrics)
        Create a named thread pool
        Parameters:
        coreThreads - number of threads
        maxThreads - max number of threads
        timeOut - core thread time out
        units - core thread time out units
        name - thread pool name
        queue - queue to use for tasks
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ThreadPoolExecutor
      • createThreadPool

        public ThreadPoolExecutor createThreadPool​(int coreThreads,
                                                   int maxThreads,
                                                   long timeOut,
                                                   TimeUnit units,
                                                   String name,
                                                   BlockingQueue<Runnable> queue,
                                                   OptionalInt priority,
                                                   boolean emitThreadPoolMetrics)
        Create a named thread pool
        Parameters:
        coreThreads - number of threads
        maxThreads - max number of threads
        timeOut - core thread time out
        units - core thread time out units
        name - thread pool name
        queue - queue to use for tasks
        priority - thread priority
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ThreadPoolExecutor
      • createScheduledExecutorService

        public ScheduledThreadPoolExecutor createScheduledExecutorService​(int numThreads,
                                                                          String name,
                                                                          boolean emitThreadPoolMetrics)
        Create a named ScheduledThreadPool
        Parameters:
        numThreads - number of threads
        name - thread pool name
        emitThreadPoolMetrics - When set to true will emit metrics and register the metrics in a static registry. After the thread pool is deleted, there will still be metrics objects related to it in the static registry. There is no way to clean these left over objects up therefore its recommended that this option only be set true for long lived thread pools. Creating lots of short lived thread pools and registering them can lead to out of memory errors over long time periods.
        Returns:
        ScheduledThreadPoolExecutor