https://issues.apache.org/jira/browse/AMQ-5417 - use proper classloader in TaskRunnerFactory

This commit is contained in:
Dejan Bosanac 2014-10-29 11:30:15 +01:00
parent adafdfe97d
commit dffccb1c7d
2 changed files with 9 additions and 0 deletions

View File

@ -1202,6 +1202,7 @@ public class BrokerService implements Service {
if (this.taskRunnerFactory == null) {
this.taskRunnerFactory = new TaskRunnerFactory("ActiveMQ BrokerService["+getBrokerName()+"] Task", getTaskRunnerPriority(), true, 1000,
isDedicatedTaskRunner());
this.taskRunnerFactory.setThreadClassLoader(this.getClass().getClassLoader());
}
return this.taskRunnerFactory;
}

View File

@ -53,6 +53,7 @@ public class TaskRunnerFactory implements Executor {
private final AtomicBoolean initDone = new AtomicBoolean(false);
private int maxThreadPoolSize = Integer.MAX_VALUE;
private RejectedExecutionHandler rejectedTaskHandler = null;
private ClassLoader threadClassLoader;
public TaskRunnerFactory() {
this("ActiveMQ Task");
@ -172,6 +173,9 @@ public class TaskRunnerFactory implements Executor {
Thread thread = new Thread(runnable, threadName);
thread.setDaemon(daemon);
thread.setPriority(priority);
if (threadClassLoader != null) {
thread.setContextClassLoader(threadClassLoader);
}
LOG.trace("Created thread[{}]: {}", threadName, thread);
return thread;
@ -239,6 +243,10 @@ public class TaskRunnerFactory implements Executor {
this.maxThreadPoolSize = maxThreadPoolSize;
}
public void setThreadClassLoader(ClassLoader threadClassLoader) {
this.threadClassLoader = threadClassLoader;
}
public RejectedExecutionHandler getRejectedTaskHandler() {
return rejectedTaskHandler;
}