diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java index 5c36034601..3af707589c 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -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; } diff --git a/activemq-client/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java b/activemq-client/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java index 86f4f3fac0..d6b1938dd4 100755 --- a/activemq-client/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java +++ b/activemq-client/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java @@ -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; }