Class ThreadPools
- java.lang.Object
-
- org.apache.accumulo.core.util.threads.ThreadPools
-
public class ThreadPools extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ThreadPools.ExecutionError
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_TIMEOUT_MILLISECS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadPoolExecutor
createExecutorService(AccumuloConfiguration conf, Property p, boolean emitThreadPoolMetrics)
Create a thread pool based on a thread pool related propertyThreadPoolExecutor
createFixedThreadPool(int numThreads, long timeOut, TimeUnit units, String name, boolean emitThreadPoolMetrics)
Create a named thread poolThreadPoolExecutor
createFixedThreadPool(int numThreads, String name, boolean emitThreadPoolMetrics)
Create a named thread poolThreadPoolExecutor
createFixedThreadPool(int numThreads, String name, BlockingQueue<Runnable> queue, boolean emitThreadPoolMetrics)
Create a named thread poolScheduledThreadPoolExecutor
createGeneralScheduledExecutorService(AccumuloConfiguration conf)
ScheduledThreadPoolExecutor
createScheduledExecutorService(int numThreads, String name, boolean emitThreadPoolMetrics)
Create a named ScheduledThreadPoolThreadPoolExecutor
createThreadPool(int coreThreads, int maxThreads, long timeOut, TimeUnit units, String name, boolean emitThreadPoolMetrics)
Create a named thread poolThreadPoolExecutor
createThreadPool(int coreThreads, int maxThreads, long timeOut, TimeUnit units, String name, BlockingQueue<Runnable> queue, boolean emitThreadPoolMetrics)
Create a named thread poolThreadPoolExecutor
createThreadPool(int coreThreads, int maxThreads, long timeOut, TimeUnit units, String name, BlockingQueue<Runnable> queue, OptionalInt priority, boolean emitThreadPoolMetrics)
Create a named thread poolstatic void
ensureRunning(ScheduledFuture<?> future, String message)
static ThreadPools
getClientThreadPools(Thread.UncaughtExceptionHandler ueh)
static ThreadPools
getServerThreadPools()
static void
resizePool(ThreadPoolExecutor pool, IntSupplier maxThreads, String poolName)
Resize ThreadPoolExecutor based on current value of maxThreadsstatic void
resizePool(ThreadPoolExecutor pool, AccumuloConfiguration conf, Property p)
Resize ThreadPoolExecutor based on current value of Property pstatic void
watchCriticalFixedDelay(AccumuloConfiguration aconf, long intervalMillis, Runnable runnable)
static void
watchCriticalScheduledTask(ScheduledFuture<?> future)
static void
watchNonCriticalScheduledTask(ScheduledFuture<?> future)
-
-
-
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()
-
getClientThreadPools
public static final ThreadPools getClientThreadPools(Thread.UncaughtExceptionHandler ueh)
-
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)
-
ensureRunning
public static void ensureRunning(ScheduledFuture<?> future, String message)
-
resizePool
public static void resizePool(ThreadPoolExecutor pool, IntSupplier maxThreads, String poolName)
Resize ThreadPoolExecutor based on current value of maxThreads- Parameters:
pool
- the ThreadPoolExecutor to modifymaxThreads
- supplier of maxThreads valuepoolName
- 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 modifyconf
- the AccumuloConfigurationp
- 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 configurationp
- thread pool related propertyemitThreadPoolMetrics
- 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 threadsname
- thread pool nameemitThreadPoolMetrics
- 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 threadsname
- thread pool namequeue
- queue to use for tasksemitThreadPoolMetrics
- 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 threadstimeOut
- core thread time outunits
- core thread time out unitsname
- thread pool nameemitThreadPoolMetrics
- 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 threadsmaxThreads
- max number of threadstimeOut
- core thread time outunits
- core thread time out unitsname
- thread pool nameemitThreadPoolMetrics
- 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 threadsmaxThreads
- max number of threadstimeOut
- core thread time outunits
- core thread time out unitsname
- thread pool namequeue
- queue to use for tasksemitThreadPoolMetrics
- 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 threadsmaxThreads
- max number of threadstimeOut
- core thread time outunits
- core thread time out unitsname
- thread pool namequeue
- queue to use for taskspriority
- thread priorityemitThreadPoolMetrics
- 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
-
createGeneralScheduledExecutorService
public ScheduledThreadPoolExecutor createGeneralScheduledExecutorService(AccumuloConfiguration conf)
-
createScheduledExecutorService
public ScheduledThreadPoolExecutor createScheduledExecutorService(int numThreads, String name, boolean emitThreadPoolMetrics)
Create a named ScheduledThreadPool- Parameters:
numThreads
- number of threadsname
- thread pool nameemitThreadPoolMetrics
- 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
-
-