Author: cwiklik Date: Wed Dec 14 16:09:45 2011 New Revision: 1214317 URL: http://svn.apache.org/viewvc?rev=1214317&view=rev Log: UIMA-2309 Call allowCoreThreadTimeout() method on ThreadPoolTaskExecutor only when running in 1.6+jvm otherwise call setCorePoolSize(0)
Modified: uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java Modified: uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java?rev=1214317&r1=1214316&r2=1214317&view=diff ============================================================================== --- uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java (original) +++ uima/uima-as/trunk/uimaj-as-activemq/src/main/java/org/apache/uima/adapter/jms/activemq/UimaDefaultMessageListenerContainer.java Wed Dec 14 16:09:45 2011 @@ -19,6 +19,7 @@ package org.apache.uima.adapter.jms.activemq; +import java.lang.reflect.Method; import java.net.ConnectException; import java.util.ArrayList; import java.util.Iterator; @@ -957,9 +958,19 @@ public class UimaDefaultMessageListenerC if (taskExecutor != null && taskExecutor instanceof ThreadPoolTaskExecutor) { // Modify task executor to terminate idle threads. While the thread terminates // it calls destroy() method on the pinned instance of AE - ((ThreadPoolTaskExecutor) taskExecutor).getThreadPoolExecutor().allowCoreThreadTimeOut(true); - ((ThreadPoolTaskExecutor) taskExecutor).getThreadPoolExecutor().setKeepAliveTime(1000, TimeUnit.MILLISECONDS); - ((ThreadPoolTaskExecutor) taskExecutor).setWaitForTasksToCompleteOnShutdown(true); + + // java 5 ThreadPoolExecutor doesnt implement allowCoreThreadTimeout Method. + // Use alternate mechanism to passivate threads in the pool. + try { + Method m = ((ThreadPoolTaskExecutor) taskExecutor). + getThreadPoolExecutor().getClass().getMethod("allowCoreThreadTimeOut", boolean.class); + m.invoke(((ThreadPoolTaskExecutor) taskExecutor).getThreadPoolExecutor(), true); + } catch ( NoSuchMethodException e) { + ((ThreadPoolTaskExecutor) taskExecutor).getThreadPoolExecutor().setCorePoolSize(0); + } + // ((ThreadPoolTaskExecutor) taskExecutor).getThreadPoolExecutor().allowCoreThreadTimeOut(true); + ((ThreadPoolTaskExecutor) taskExecutor).getThreadPoolExecutor().setKeepAliveTime(1000, TimeUnit.MILLISECONDS); + ((ThreadPoolTaskExecutor) taskExecutor).setWaitForTasksToCompleteOnShutdown(true); ((ThreadPoolTaskExecutor) taskExecutor).shutdown(); } else if (concurrentListener != null) { shutdownTaskExecutor(concurrentListener.getTaskExecutor(), stopImmediate);