Author: davsclaus Date: Mon Nov 8 17:29:50 2010 New Revision: 1032645 URL: http://svn.apache.org/viewvc?rev=1032645&view=rev Log: CAMEL-3192: Thread name syntax now support camelId so if you run multiple Camel apps in same JVM its easier to differentiate.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java?rev=1032645&r1=1032644&r2=1032645&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExecutorServiceStrategy.java Mon Nov 8 17:29:50 2010 @@ -45,7 +45,7 @@ public class DefaultExecutorServiceStrat private static final Log LOG = LogFactory.getLog(DefaultExecutorServiceStrategy.class); private final List<ExecutorService> executorServices = new ArrayList<ExecutorService>(); private final CamelContext camelContext; - private String threadNamePattern = "Camel Thread ${counter} - ${name}"; + private String threadNamePattern; private String defaultThreadPoolProfileId; private final Map<String, ThreadPoolProfile> threadPoolProfiles = new HashMap<String, ThreadPoolProfile>(); @@ -132,7 +132,9 @@ public class DefaultExecutorServiceStrat } public void setThreadNamePattern(String threadNamePattern) { - this.threadNamePattern = threadNamePattern; + // must set camel id here in the pattern and let the other placeholders be resolved by ExecutorServiceHelper + String name = threadNamePattern.replaceFirst("\\$\\{camelId\\}", camelContext.getName()); + this.threadNamePattern = name; } public ExecutorService lookup(Object source, String name, String executorServiceRef) { @@ -350,7 +352,10 @@ public class DefaultExecutorServiceStrat @Override protected void doStart() throws Exception { - // noop + if (threadNamePattern == null) { + // set default name pattern which includes the camel context name + threadNamePattern = "Camel (" + camelContext.getName() + ") thread #${counter} - ${name}"; + } } @Override Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java?rev=1032645&r1=1032644&r2=1032645&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ExecutorServiceStrategy.java Mon Nov 8 17:29:50 2010 @@ -89,11 +89,12 @@ public interface ExecutorServiceStrategy /** * Sets the thread name pattern used for creating the full thread name. * <p/> - * The default pattern is: <tt>Camel Thread ${counter} - ${name}</tt> - * </br> - * Where <tt>${counter}</tt> is a unique incrementing counter. - * And <tt>${name}</tt> is the regular thread name. - * And <tt>${longName}</tt> is the long thread name which can includes endpoint parameters etc. + * The default pattern is: <tt>Camel (${camelId}) thread #${counter} - ${name}</tt> + * <p/> + * Where <tt>${camelId}</tt> is the name of the {...@link org.apache.camel.CamelContext} + * <br/>and <tt>${counter}</tt> is a unique incrementing counter. + * <br/>and <tt>${name}</tt> is the regular thread name. + * <br/>You can also use <tt>${longName}</tt> is the long thread name which can includes endpoint parameters etc. * * @param pattern the pattern * @throws IllegalArgumentException if the pattern is invalid. Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java?rev=1032645&r1=1032644&r2=1032645&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/concurrent/ExecutorServiceHelper.java Mon Nov 8 17:29:50 2010 @@ -53,7 +53,7 @@ public final class ExecutorServiceHelper private ExecutorServiceHelper() { } - private static synchronized int nextThreadCounter() { + private static int nextThreadCounter() { return threadCounter.getAndIncrement(); } @@ -155,7 +155,9 @@ public final class ExecutorServiceHelper * @param name ${name} in the pattern name * @param daemon whether the threads is daemon or not * @return the created pool + * @deprecated using cached thread pool is discouraged as they have no upper bound and can overload the JVM */ + @Deprecated public static ExecutorService newCachedThreadPool(final String pattern, final String name, final boolean daemon) { return Executors.newCachedThreadPool(new ThreadFactory() { public Thread newThread(Runnable r) { Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java?rev=1032645&r1=1032644&r2=1032645&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultExecutorServiceStrategyTest.java Mon Nov 8 17:29:50 2010 @@ -28,14 +28,14 @@ import org.apache.camel.ThreadPoolReject */ public class DefaultExecutorServiceStrategyTest extends ContextTestSupport { - public void testGetThreadName() throws Exception { + public void testGetThreadNameDefaultPattern() throws Exception { String foo = context.getExecutorServiceStrategy().getThreadName("foo"); String bar = context.getExecutorServiceStrategy().getThreadName("bar"); assertNotSame(foo, bar); - assertTrue(foo.startsWith("Camel Thread ")); + assertTrue(foo.startsWith("Camel (" + context.getName() + ") thread ")); assertTrue(foo.endsWith("foo")); - assertTrue(bar.startsWith("Camel Thread ")); + assertTrue(bar.startsWith("Camel (" + context.getName() + ") thread ")); assertTrue(bar.endsWith("bar")); } @@ -51,6 +51,18 @@ public class DefaultExecutorServiceStrat assertTrue(bar.endsWith(" - bar")); } + public void testGetThreadNameCustomPatternCamelId() throws Exception { + context.getExecutorServiceStrategy().setThreadNamePattern("#${camelId} - #${counter} - ${name}"); + String foo = context.getExecutorServiceStrategy().getThreadName("foo"); + String bar = context.getExecutorServiceStrategy().getThreadName("bar"); + + assertNotSame(foo, bar); + assertTrue(foo.startsWith("#" + context.getName() + " - #")); + assertTrue(foo.endsWith(" - foo")); + assertTrue(bar.startsWith("#" + context.getName() + " - #")); + assertTrue(bar.endsWith(" - bar")); + } + public void testGetThreadNameCustomPatternWithDollar() throws Exception { context.getExecutorServiceStrategy().setThreadNamePattern("Hello - ${name}"); String foo = context.getExecutorServiceStrategy().getThreadName("foo$bar");