From ec4cbf7b34b19dbd9b4b542067461c2593380cc7 Mon Sep 17 00:00:00 2001 From: Bernd Gutjahr Date: Tue, 19 Apr 2016 13:55:30 +0200 Subject: [PATCH] abstracted global client thread pools from ThreadPoolExecutor as implementation Changed the ActiveMQClient interface to expose global thread pools as ExecutorService and ScheduledExecutorService interface. This is necessary to allow injecting thread pool implementations that are not based on ThreadPoolExecutor or ScheduledThreadPoolExecutor. --- .../artemis/api/core/client/ActiveMQClient.java | 12 +++++++----- .../activemq/artemis/ClientThreadPoolsTest.java | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java index abc3a5d99d..3f5dcb9ec4 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ActiveMQClient.java @@ -19,7 +19,9 @@ package org.apache.activemq.artemis.api.core.client; import java.net.URI; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadFactory; @@ -136,11 +138,11 @@ public final class ActiveMQClient { public static final String SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY = "activemq.artemis.client.global.scheduled.thread.pool.core.size"; - private static ThreadPoolExecutor globalThreadPool; + private static ExecutorService globalThreadPool; private static boolean injectedPools = false; - private static ScheduledThreadPoolExecutor globalScheduledThreadPool; + private static ScheduledExecutorService globalScheduledThreadPool; static { @@ -195,7 +197,7 @@ public final class ActiveMQClient { } /** Warning: This method has to be called before any clients or servers is started on the JVM otherwise previous ServerLocator would be broken after this call. */ - public static synchronized void injectPools(ThreadPoolExecutor globalThreadPool, ScheduledThreadPoolExecutor scheduledThreadPool) { + public static synchronized void injectPools(ExecutorService globalThreadPool, ScheduledExecutorService scheduledThreadPool) { if (globalThreadPool == null || scheduledThreadPool == null) throw new IllegalArgumentException("thread pools must not be null"); @@ -207,7 +209,7 @@ public final class ActiveMQClient { injectedPools = true; } - public static synchronized ThreadPoolExecutor getGlobalThreadPool() { + public static synchronized ExecutorService getGlobalThreadPool() { if (globalThreadPool == null) { ThreadFactory factory = AccessController.doPrivileged(new PrivilegedAction() { @Override @@ -226,7 +228,7 @@ public final class ActiveMQClient { return globalThreadPool; } - public static synchronized ScheduledThreadPoolExecutor getGlobalScheduledThreadPool() { + public static synchronized ScheduledExecutorService getGlobalScheduledThreadPool() { if (globalScheduledThreadPool == null) { ThreadFactory factory = AccessController.doPrivileged(new PrivilegedAction() { @Override diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/ClientThreadPoolsTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/ClientThreadPoolsTest.java index a3dc213d2c..f9cd852e85 100644 --- a/artemis-core-client/src/test/java/org/apache/activemq/artemis/ClientThreadPoolsTest.java +++ b/artemis-core-client/src/test/java/org/apache/activemq/artemis/ClientThreadPoolsTest.java @@ -177,7 +177,7 @@ public class ClientThreadPoolsTest { threadPoolField.setAccessible(true); scheduledThreadPoolField.setAccessible(true); - ThreadPoolExecutor threadPool = ActiveMQClient.getGlobalThreadPool(); + ThreadPoolExecutor threadPool = (ThreadPoolExecutor) ActiveMQClient.getGlobalThreadPool(); final CountDownLatch doneMax = new CountDownLatch(expectedMax); final CountDownLatch latch = new CountDownLatch(1);