mirror of https://github.com/apache/activemq.git
Add more configuration options to TaskRunnerFactory
(cherry picked from commit ebcc1b4eae
)
This commit is contained in:
parent
b32be1bb11
commit
543851ba54
|
@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
|
|||
* Manages the thread pool for long running tasks. Long running tasks are not
|
||||
* always active but when they are active, they may need a few iterations of
|
||||
* processing for them to become idle. The manager ensures that each task is
|
||||
* processes but that no one task overtakes the system. This is kinda like
|
||||
* processes but that no one task overtakes the system. This is somewhat like
|
||||
* cooperative multitasking.
|
||||
*
|
||||
* @org.apache.xbean.XBean
|
||||
|
@ -51,7 +51,7 @@ public class TaskRunnerFactory implements Executor {
|
|||
private boolean dedicatedTaskRunner;
|
||||
private long shutdownAwaitTermination = 30000;
|
||||
private final AtomicBoolean initDone = new AtomicBoolean(false);
|
||||
private int maxThreadPoolSize = Integer.MAX_VALUE;
|
||||
private int maxThreadPoolSize = getDefaultMaximumPoolSize();
|
||||
private RejectedExecutionHandler rejectedTaskHandler = null;
|
||||
private ClassLoader threadClassLoader;
|
||||
|
||||
|
@ -166,7 +166,7 @@ public class TaskRunnerFactory implements Executor {
|
|||
}
|
||||
|
||||
protected ExecutorService createDefaultExecutor() {
|
||||
ThreadPoolExecutor rc = new ThreadPoolExecutor(0, getMaxThreadPoolSize(), getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
|
||||
ThreadPoolExecutor rc = new ThreadPoolExecutor(getDefaultCorePoolSize(), getMaxThreadPoolSize(), getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
String threadName = name + "-" + id.incrementAndGet();
|
||||
|
@ -182,14 +182,16 @@ public class TaskRunnerFactory implements Executor {
|
|||
LOG.error("Error in thread '{}'", t.getName(), e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
LOG.trace("Created thread[{}]: {}", threadName, thread);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
|
||||
if (rejectedTaskHandler != null) {
|
||||
rc.setRejectedExecutionHandler(rejectedTaskHandler);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -269,6 +271,14 @@ public class TaskRunnerFactory implements Executor {
|
|||
this.shutdownAwaitTermination = shutdownAwaitTermination;
|
||||
}
|
||||
|
||||
private static int getDefaultCorePoolSize() {
|
||||
return Integer.getInteger("org.apache.activemq.thread.TaskRunnerFactory.corePoolSize", 0);
|
||||
}
|
||||
|
||||
private static int getDefaultMaximumPoolSize() {
|
||||
return Integer.getInteger("org.apache.activemq.thread.TaskRunnerFactory.maximumPoolSize", Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
private static int getDefaultKeepAliveTime() {
|
||||
return Integer.getInteger("org.apache.activemq.thread.TaskRunnerFactory.keepAliveTime", 30);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue