Skip to content

Commit

Permalink
[sre] Add configuration property for specifying the max number of thr…
Browse files Browse the repository at this point in the history
…eads.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 1, 2016
1 parent ec2c958 commit 8df40a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Expand Up @@ -184,11 +184,25 @@ public final class JanusConfig {
public static final String MAX_NUMBER_OF_THREADS_IN_EXECUTOR_NAME = "janus.executors.threads.max"; //$NON-NLS-1$

/**
* Indicates the maximal number of threads to keep in the pool, even if they are idle, unless {@code allowCoreThreadTimeOut} is set.
* Indicates the maximal number of threads to keep in the pool.
*
* @see #MAX_NUMBER_OF_THREADS_IN_EXECUTOR_NAME
*/
public static final int MAX_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE = 50;
public static final int MAX_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE = 512;

/**
* Name of the property that contains the minimal number of threads in the pool.
*
* @see #MIN_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE
*/
public static final String MIN_NUMBER_OF_THREADS_IN_EXECUTOR_NAME = "janus.executors.threads.min"; //$NON-NLS-1$

/**
* Indicates the minimal number of threads to keep in the pool, even if they are idle.
*
* @see #MIN_NUMBER_OF_THREADS_IN_EXECUTOR_NAME
*/
public static final int MIN_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE = 16;

/**
* Name of the property that contains the numbers of seconds that the kernel is waiting for thread terminations before timeout.
Expand Down Expand Up @@ -259,6 +273,7 @@ public static void getDefaultValues(Properties defaultValues) {
defaultValues.put(VERBOSE_LEVEL_NAME, VERBOSE_LEVEL_VALUE);
defaultValues.put(LOGGING_PROPERTY_FILE_NAME, LOGGING_PROPERTY_FILE_VALUE);
defaultValues.put(HAZELCAST_LOGGER_FACTORY_NAME, HAZELCAST_LOGGER_FACTORY_VALUE);
defaultValues.put(MIN_NUMBER_OF_THREADS_IN_EXECUTOR_NAME, Integer.toString(MIN_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE));
defaultValues.put(MAX_NUMBER_OF_THREADS_IN_EXECUTOR_NAME, Integer.toString(MAX_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE));
defaultValues.put(KERNEL_THREAD_TIMEOUT_NAME, Integer.toString(KERNEL_THREAD_TIMEOUT_VALUE));
defaultValues.put(KERNEL_THREAD_PURGE_DELAY_NAME, Integer.toString(KERNEL_THREAD_PURGE_DELAY_VALUE));
Expand Down
Expand Up @@ -51,8 +51,8 @@ public class JdkScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor
*/
@Inject
public JdkScheduledThreadPoolExecutor(ThreadFactory factory) {
super(JanusConfig.getSystemPropertyAsInteger(JanusConfig.MAX_NUMBER_OF_THREADS_IN_EXECUTOR_NAME,
JanusConfig.MAX_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE), factory);
super(JanusConfig.getSystemPropertyAsInteger(JanusConfig.MIN_NUMBER_OF_THREADS_IN_EXECUTOR_NAME,
JanusConfig.MIN_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE), factory);
}

/**
Expand Down
Expand Up @@ -43,7 +43,7 @@
*/
public class JdkThreadPoolExecutor extends ThreadPoolExecutor {

private static final long TIMEOUT = 60;
private static final long TIMEOUT = 120;

private ListenerCollection<JdkTaskListener> listeners;

Expand All @@ -61,7 +61,20 @@ public JdkThreadPoolExecutor(ThreadFactory factory) {
* @param factory - thread factory.
*/
public JdkThreadPoolExecutor(int poolSize, ThreadFactory factory) {
super(poolSize, Integer.MAX_VALUE, TIMEOUT, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory);
this(JanusConfig.getSystemPropertyAsInteger(JanusConfig.MIN_NUMBER_OF_THREADS_IN_EXECUTOR_NAME,
JanusConfig.MIN_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE),
poolSize, factory);
}

/**
* @param minPoolSize - minimal number of threads in the pool.
* @param maxPoolSize - maximal number of threads in the pool.
* @param factory - thread factory.
*/
public JdkThreadPoolExecutor(int minPoolSize, int maxPoolSize, ThreadFactory factory) {
super(Math.max(0, Math.min(minPoolSize, maxPoolSize)),
Math.max(0, maxPoolSize),
TIMEOUT, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory);
}

/**
Expand Down

0 comments on commit 8df40a0

Please sign in to comment.