ARTEMIS-482 Assign dedicated ThreadPool for InVMTransport

This commit is contained in:
Martyn Taylor 2016-04-14 12:46:57 +01:00
parent 5678d1ad2b
commit fc8a1eff43
1 changed files with 22 additions and 2 deletions

View File

@ -22,11 +22,17 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor; 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.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.ActiveMQComponent;
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle; 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.AbstractConnector;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor; import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener; import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener;
@ -86,6 +92,20 @@ public class InVMConnector extends AbstractConnector {
private final Executor closeExecutor; 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<Runnable>(), Executors.defaultThreadFactory());
}
else {
threadPoolExecutor = Executors.newFixedThreadPool(ActiveMQClient.globalThreadMaxPoolSize);
}
}
return threadPoolExecutor;
}
public InVMConnector(final Map<String, Object> configuration, public InVMConnector(final Map<String, Object> configuration,
final BufferHandler handler, final BufferHandler handler,
final ClientConnectionLifeCycleListener listener, final ClientConnectionLifeCycleListener listener,
@ -101,7 +121,7 @@ public class InVMConnector extends AbstractConnector {
this.closeExecutor = closeExecutor; this.closeExecutor = closeExecutor;
executorFactory = new OrderedExecutorFactory(threadPool); executorFactory = new OrderedExecutorFactory(getInVMExecutor());
InVMRegistry registry = InVMRegistry.instance; InVMRegistry registry = InVMRegistry.instance;