Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 54478 invoked from network); 8 Nov 2010 17:30:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Nov 2010 17:30:38 -0000 Received: (qmail 53052 invoked by uid 500); 8 Nov 2010 17:31:10 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 53000 invoked by uid 500); 8 Nov 2010 17:31:09 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 52993 invoked by uid 99); 8 Nov 2010 17:31:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Nov 2010 17:31:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Nov 2010 17:31:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 485F323889C5; Mon, 8 Nov 2010 17:29:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1032645 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ main/java/org/apache/camel/spi/ main/java/org/apache/camel/util/concurrent/ test/java/org/apache/camel/impl/ Date: Mon, 08 Nov 2010 17:29:51 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101108172951.485F323889C5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 executorServices = new ArrayList(); private final CamelContext camelContext; - private String threadNamePattern = "Camel Thread ${counter} - ${name}"; + private String threadNamePattern; private String defaultThreadPoolProfileId; private final Map threadPoolProfiles = new HashMap(); @@ -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. *

- * The default pattern is: Camel Thread ${counter} - ${name} - *
- * Where ${counter} is a unique incrementing counter. - * And ${name} is the regular thread name. - * And ${longName} is the long thread name which can includes endpoint parameters etc. + * The default pattern is: Camel (${camelId}) thread #${counter} - ${name} + *

+ * Where ${camelId} is the name of the {@link org.apache.camel.CamelContext} + *
and ${counter} is a unique incrementing counter. + *
and ${name} is the regular thread name. + *
You can also use ${longName} 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");