/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
/** * Initializes the global thread pools properties from System properties. This method will update the global * thread pool configuration based on defined System properties (or defaults if they are not set). * The System properties key names are as follow: * * ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY="activemq.artemis.client.global.thread.pool.max.size" * ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY="activemq.artemis.client.global.scheduled.thread.pool.core.size * * The min value for max thread pool size is 2. If the value is not -1, but lower than 2, it will be ignored and will default to 2. * A value of -1 configures an unbounded thread pool. * * Note: If global thread pools have already been created, they will not be updated with these new values. */ public static void initializeGlobalThreadPoolProperties() { setGlobalThreadPoolProperties(Integer.valueOf(System.getProperty(ActiveMQClient.THREAD_POOL_MAX_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_GLOBAL_THREAD_POOL_MAX_SIZE)), Integer.valueOf(System.getProperty(ActiveMQClient.SCHEDULED_THREAD_POOL_SIZE_PROPERTY_KEY, "" + ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE))); }
ActiveMQClient.setGlobalThreadPoolProperties(threadPoolMaxSizeValue, scheduledThreadPoolMaxSizeValue);
ActiveMQClient.setGlobalThreadPoolProperties(threadPoolMaxSizeValue, scheduledThreadPoolMaxSizeValue);
@Test public void testSmallPool() throws Exception { int testMaxSize = 2; int testScheduleSize = 9; ActiveMQClient.setGlobalThreadPoolProperties(testMaxSize, testScheduleSize); ActiveMQClient.clearThreadPools(); testSystemPropertiesThreadPoolSettings(testMaxSize, testScheduleSize); }
@Test public void testStaticPropertiesThreadPoolSettings() throws Exception { int testMaxSize = 999; int testScheduleSize = 9; ActiveMQClient.setGlobalThreadPoolProperties(testMaxSize, testScheduleSize); ActiveMQClient.clearThreadPools(); testSystemPropertiesThreadPoolSettings(testMaxSize, testScheduleSize); }
@Test public void testShutdownPoolInUse() throws Exception { ActiveMQClient.setGlobalThreadPoolProperties(10, 1); ActiveMQClient.clearThreadPools(); final CountDownLatch inUse = new CountDownLatch(1); final CountDownLatch neverLeave = new CountDownLatch(1); ActiveMQClient.getGlobalThreadPool().execute(new Runnable() { @Override public void run() { System.err.println("Hello!"); try { inUse.countDown(); neverLeave.await(); } catch (Exception e) { e.printStackTrace(); neverLeave.countDown(); } } }); Assert.assertTrue(inUse.await(10, TimeUnit.SECONDS)); ActiveMQClient.clearThreadPools(100, TimeUnit.MILLISECONDS); Assert.assertTrue(neverLeave.await(10, TimeUnit.SECONDS)); }
@Test public void testCoreClientWithGlobalThreadPoolParamtersChanged() throws Exception { int originalScheduled = ActiveMQClient.getGlobalScheduledThreadPoolSize(); int originalGlobal = ActiveMQClient.getGlobalThreadPoolSize(); try { ActiveMQClient.setGlobalThreadPoolProperties(2, 1); ActiveMQClient.clearThreadPools(); ServerLocator locator = createNonHALocator(false); testCoreClient(true, locator); } finally { // restoring original value otherwise future tests would be screwed up ActiveMQClient.setGlobalThreadPoolProperties(originalGlobal, originalScheduled); ActiveMQClient.clearThreadPools(); } }