From dffccb1c7dc8e4b4a6282fd5056dfd854d2d2a9b Mon Sep 17 00:00:00 2001 From: Dejan Bosanac Date: Wed, 29 Oct 2014 11:30:15 +0100 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5417 - use proper classloader in TaskRunnerFactory --- .../java/org/apache/activemq/broker/BrokerService.java | 1 + .../org/apache/activemq/thread/TaskRunnerFactory.java | 8 ++++++++ 2 files changed, 9 insertions(+) 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; }