public final class Exec
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
Exec.DefaultThreadFactory
Default thread factory.
|
static class |
Exec.FinishingThreadPoolExecutor
This is a wrapper for a thread-pool executor which accepts runnable tasks
and can wait until all of them are finished.
|
(package private) static class |
Exec.PrivilegedThreadFactory
Privileged thread factor.
|
| Modifier and Type | Field and Description |
|---|---|
static double |
DEFAULT_CPU_UTILIZATION_FACTOR
CPU utilization factor, leave 5% for computer and GUI.
|
static int |
DEFAULT_MAX_THREADS
The default for the maximum allowed number of threads.
|
static double |
DEFAULT_WAIT_TO_COMPUTE_RATIO
Default wait-to-compute ratio.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
calcNumThreads(double cpuUtilizationFactor,
double waitToComputeRatio,
int maxThreads)
Calculate a useful number of threads for a task.
|
static java.util.concurrent.ThreadPoolExecutor |
createDefaultExecutor()
Create a default thread pool executor with a default number of threads,
a keep-alive time of 0, a linked blocking queue, and a rejection handler
which discards all unexecutable threads.
|
static java.util.concurrent.ThreadPoolExecutor |
createDefaultExecutor(double cpuUtilizationFactor,
double waitToComputeRatio,
int maxThreads)
Create a default thread pool executor with a useful number of threads,
a keep alive time of 0, a linked blocking queue, and a rejection handler
which discards all unexecutable threads.
|
static java.util.concurrent.ThreadPoolExecutor |
createDefaultExecutor(int maxThreads)
Create a default thread pool executor with a restricted but default number of threads,
a keep-alive time of 0, a linked blocking queue, and a rejection handler
which discards all unexecutable threads.
|
static java.util.concurrent.ThreadPoolExecutor |
createDefaultExecutor(java.lang.String basicThreadName,
double cpuUtilizationFactor,
double waitToComputeRatio,
int maxThreads)
Create a default thread pool executor with a useful number of threads,
a keep-alive time of 0, a linked blocking queue, and a rejection handler
which discards all unexecutable threads.
|
static java.util.concurrent.ThreadFactory |
defaultNamedThreadFactory(java.lang.String baseName)
Get a default thread factory where threads get an individual name
made up from the given basic name.
|
static java.util.concurrent.ThreadFactory |
privilegedNamedThreadFactory(java.lang.String baseName)
Get a privileged thread factory where threads get an individual name
made up from the given basic name.
|
static java.util.concurrent.ThreadFactory |
privilegedNamedThreadFactory(java.lang.String baseName,
java.lang.ClassLoader classLoader)
Get a privileged thread factory where threads get an individual name
made up from the given basic name.
|
public static final int DEFAULT_MAX_THREADS
"caff.exec.maxthreads",
preferably at startup via command line, but at least before this class is loaded, e.g. statically
in the startup class or early in the startup method.public static final double DEFAULT_WAIT_TO_COMPUTE_RATIO
public static final double DEFAULT_CPU_UTILIZATION_FACTOR
public static int calcNumThreads(double cpuUtilizationFactor,
double waitToComputeRatio,
int maxThreads)
This uses the number of CPUs as a base together with the parameters, to calculate a useful number of threads for a thread pool.
cpuUtilizationFactor - how much of the CPU should be used to run the threads,
a number between 0.0 (none) and 1.0 (everything).
Leave a bit of room for other tasks your computer has to perform.waitToComputeRatio - value which defines the ratio of the time your tasks are waiting for input
against the time they spend actual computing. A number between
0.0 (no waiting, only computing) and 1.0 (no computing,
only waiting).maxThreads - upper limit to the number of threads, at least 1@NotNull public static java.util.concurrent.ThreadPoolExecutor createDefaultExecutor(double cpuUtilizationFactor, double waitToComputeRatio, int maxThreads)
cpuUtilizationFactor - how much of the CPU should be used to run the threads,
a number between 0.0 (none) and 1.0 (everything).
Leave a bit of room for other tasks your computer has to perform.waitToComputeRatio - value which defines the ratio of the time your tasks are waiting for input
against the time they spend actual computing. A number between
0.0 (no waiting, only computing) and 1.0 (no computing,
only waiting).maxThreads - upper limit to the number of threads, at least 1@NotNull public static java.util.concurrent.ThreadPoolExecutor createDefaultExecutor(int maxThreads)
createDefaultExecutor(double,double,int) with
DEFAULT_CPU_UTILIZATION_FACTOR and DEFAULT_WAIT_TO_COMPUTE_RATIO.maxThreads - upper limit to the created number of threads@NotNull public static java.util.concurrent.ThreadPoolExecutor createDefaultExecutor()
createDefaultExecutor(double,double,int) with
DEFAULT_CPU_UTILIZATION_FACTOR, DEFAULT_WAIT_TO_COMPUTE_RATIO,
and DEFAULT_MAX_THREADS.@NotNull public static java.util.concurrent.ThreadPoolExecutor createDefaultExecutor(@NotNull java.lang.String basicThreadName, double cpuUtilizationFactor, double waitToComputeRatio, int maxThreads)
basicThreadName - basic name used for threads, see defaultNamedThreadFactory(String)cpuUtilizationFactor - how much of the CPU should be used to run the threads,
a number between 0.0 (none) and 1.0 (everything).
Leave a bit of room for other tasks your computer has to perform.waitToComputeRatio - value which defines the ratio of the time your task are waiting for input
against the time they spend actual computing. A number between
0.0 (no waiting, only computing) and 1.0 (no computing,
only waiting).maxThreads - upper limit to the number of threads, at least 1@NotNull public static java.util.concurrent.ThreadFactory defaultNamedThreadFactory(@NotNull java.lang.String baseName)
Executors.defaultThreadFactory(),
only you can set a dedicated name.
Threads will get individual names made up from the given baseName,
a pool number for the factory and a number for each thread in the individual pool
in the format <baseName>-<poolnr>-<threadnr>.
baseName - basic namebaseName@NotNull public static java.util.concurrent.ThreadFactory privilegedNamedThreadFactory(@NotNull java.lang.String baseName)
Executors.privilegedThreadFactory(),
only you can set a dedicated name.
Threads will get individual names made up from the given baseName,
a pool number for the factory and a number for each thread in the individual pool
in the format <baseName>-<poolnr>-<threadnr>.
baseName - basic namebaseName@NotNull public static java.util.concurrent.ThreadFactory privilegedNamedThreadFactory(@NotNull java.lang.String baseName, @NotNull java.lang.ClassLoader classLoader)
Executors.privilegedThreadFactory(),
only you can set a dedicated name and a dedicated class loader.
Threads will get individual names made up from the given baseName,
a pool number for the factory and a number for each thread in the individual pool
in the format <baseName>-<poolnr>-<threadnr>.
baseName - basic nameclassLoader - class loader set as context class loader in the created threadsbaseName