diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java index c1fab773d5..0783d7c0a9 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnector.java @@ -22,11 +22,17 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import org.apache.activemq.artemis.api.core.ActiveMQException; +import org.apache.activemq.artemis.api.core.client.ActiveMQClient; import org.apache.activemq.artemis.core.server.ActiveMQComponent; -import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle; +import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; import org.apache.activemq.artemis.spi.core.remoting.AbstractConnector; import org.apache.activemq.artemis.spi.core.remoting.Acceptor; import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener; @@ -86,6 +92,20 @@ public class InVMConnector extends AbstractConnector { private final Executor closeExecutor; + private static ExecutorService threadPoolExecutor; + + private static ExecutorService getInVMExecutor() { + if (threadPoolExecutor == null) { + if (ActiveMQClient.globalThreadMaxPoolSize <= -1) { + threadPoolExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), Executors.defaultThreadFactory()); + } + else { + threadPoolExecutor = Executors.newFixedThreadPool(ActiveMQClient.globalThreadMaxPoolSize); + } + } + return threadPoolExecutor; + } + public InVMConnector(final Map configuration, final BufferHandler handler, final ClientConnectionLifeCycleListener listener, @@ -101,7 +121,7 @@ public class InVMConnector extends AbstractConnector { this.closeExecutor = closeExecutor; - executorFactory = new OrderedExecutorFactory(threadPool); + executorFactory = new OrderedExecutorFactory(getInVMExecutor()); InVMRegistry registry = InVMRegistry.instance;