Allow for tuning to thread pool keep alive times as system properties.
This commit is contained in:
Timothy Bish 2013-09-04 14:16:51 -04:00
parent 1f57a6408f
commit ce5d2a9e9e
3 changed files with 20 additions and 8 deletions

View File

@ -47,10 +47,10 @@ public class TaskRunnerFactory implements Executor {
private String name;
private int priority;
private boolean daemon;
private AtomicLong id = new AtomicLong(0);
private final AtomicLong id = new AtomicLong(0);
private boolean dedicatedTaskRunner;
private long shutdownAwaitTermination = 30000;
private AtomicBoolean initDone = new AtomicBoolean(false);
private final AtomicBoolean initDone = new AtomicBoolean(false);
private int maxThreadPoolSize = Integer.MAX_VALUE;
private RejectedExecutionHandler rejectedTaskHandler = null;
@ -140,6 +140,7 @@ public class TaskRunnerFactory implements Executor {
}
}
@Override
public void execute(Runnable runnable) {
execute(runnable, name);
}
@ -164,7 +165,8 @@ public class TaskRunnerFactory implements Executor {
}
protected ExecutorService createDefaultExecutor() {
ThreadPoolExecutor rc = new ThreadPoolExecutor(0, getMaxThreadPoolSize(), 30, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
ThreadPoolExecutor rc = new ThreadPoolExecutor(0, getMaxThreadPoolSize(), getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
String threadName = name + "-" + id.incrementAndGet();
Thread thread = new Thread(runnable, threadName);
@ -253,4 +255,7 @@ public class TaskRunnerFactory implements Executor {
this.shutdownAwaitTermination = shutdownAwaitTermination;
}
private static int getDefaultKeepAliveTime() {
return Integer.getInteger("org.apache.activemq.thread.TaskRunnerFactory.keepAliveTime", 30);
}
}

View File

@ -444,10 +444,12 @@ public abstract class AbstractInactivityMonitor extends TransportFilter {
};
private ThreadPoolExecutor createExecutor() {
// TODO: This value of 10 seconds seems to low, see discussion at
// http://activemq.2283324.n4.nabble.com/InactivityMonitor-Creating-too-frequent-threads-tp4656752.html;cid=1348142445209-351
ThreadPoolExecutor exec = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory);
ThreadPoolExecutor exec = new ThreadPoolExecutor(0, Integer.MAX_VALUE, getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory);
exec.allowCoreThreadTimeOut(true);
return exec;
}
private static int getDefaultKeepAliveTime() {
return Integer.getInteger("org.apache.activemq.transport.AbstractInactivityMonitor.keepAliveTime", 30);
}
}

View File

@ -39,14 +39,15 @@ public final class SelectorManager {
private Executor selectorExecutor = createDefaultExecutor();
private Executor channelExecutor = selectorExecutor;
private LinkedList<SelectorWorker> freeWorkers = new LinkedList<SelectorWorker>();
private final LinkedList<SelectorWorker> freeWorkers = new LinkedList<SelectorWorker>();
private int maxChannelsPerWorker = 1024;
protected ExecutorService createDefaultExecutor() {
ThreadPoolExecutor rc = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
ThreadPoolExecutor rc = new ThreadPoolExecutor(0, Integer.MAX_VALUE, getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
private long i = 0;
@Override
public Thread newThread(Runnable runnable) {
this.i++;
final Thread t = new Thread(runnable, "ActiveMQ NIO Worker " + this.i);
@ -57,6 +58,10 @@ public final class SelectorManager {
return rc;
}
private static int getDefaultKeepAliveTime() {
return Integer.getInteger("org.apache.activemq.transport.nio.SelectorManager.keepAliveTime", 30);
}
public static SelectorManager getInstance() {
return SINGLETON;
}