public class ConcurrencyTools
extends java.lang.Object
shutdown()
or shutdownAndAwaitTermination()
must be called after all tasks have been submitted.Modifier and Type | Method | Description |
---|---|---|
static java.util.concurrent.ThreadPoolExecutor |
getThreadPool() |
Returns current shared thread pool.
|
static void |
setThreadPool(java.util.concurrent.ThreadPoolExecutor pool) |
Sets thread pool to any given
ThreadPoolExecutor to allow use of an alternative execution style. |
static void |
setThreadPoolCPUsAvailable(int cpus) |
Sets thread pool to reserve a given number of processor cores for foreground or other use.
|
static void |
setThreadPoolCPUsFraction(float fraction) |
Sets thread pool to a given fraction of the available processors.
|
static void |
setThreadPoolDefault() |
Sets thread pool to default of 1 background thread for each processor core.
|
static void |
setThreadPoolSingle() |
Sets thread pool to a single background thread.
|
static void |
setThreadPoolSize(int threads) |
Sets thread pool to given size.
|
static void |
shutdown() |
Disables new tasks from being submitted and closes the thread pool cleanly.
|
static void |
shutdownAndAwaitTermination() |
Closes the thread pool.
|
static <T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task) |
Queues up a task and adds a default log entry.
|
static <T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task,
java.lang.String message) |
Queues up a task and adds a log entry.
|
public static java.util.concurrent.ThreadPoolExecutor getThreadPool()
public static void setThreadPoolCPUsAvailable(int cpus)
cpus
- number of processor cores to reservepublic static void setThreadPoolCPUsFraction(float fraction)
fraction
- portion of available processors to use in thread poolpublic static void setThreadPoolDefault()
public static void setThreadPoolSingle()
public static void setThreadPoolSize(int threads)
threads
- number of threads in poolpublic static void setThreadPool(java.util.concurrent.ThreadPoolExecutor pool)
ThreadPoolExecutor
to allow use of an alternative execution style.pool
- thread pool to sharepublic static void shutdown()
public static void shutdownAndAwaitTermination()
public static <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task, java.lang.String message)
T
- type returned from the submitted tasktask
- submitted taskmessage
- logged messagepublic static <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
T
- type returned from the submitted tasktask
- submitted task