activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1081826 - /activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
Date Tue, 15 Mar 2011 16:07:38 GMT
Author: chirino
Date: Tue Mar 15 16:07:37 2011
New Revision: 1081826

URL: http://svn.apache.org/viewvc?rev=1081826&view=rev
Log:
Limit the number of threads the blocking pool will create.  The broker was spawning way to
many threads when hit concurrently with many login requests.  The max pool size is configurable
with a system property.

Modified:
    activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java

Modified: activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java?rev=1081826&r1=1081825&r2=1081826&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/ApolloThreadPool.java
Tue Mar 15 16:07:37 2011
@@ -16,26 +16,30 @@
  */
 package org.apache.activemq.apollo.util;
 
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.*;
 
 /**
  * <p>
  * Holds a singleton instance to a cached thread pool that can be used
- * to execute blocking tasks.
+ * to execute blocking tasks.  The tasks must be independent of each other
  * </p>
  *
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
 public class ApolloThreadPool {
 
-    public static final ExecutorService INSTANCE = Executors.newCachedThreadPool(new ThreadFactory()
{
+    public static final int POOL_SIZE = Integer.parseInt(System.getProperty("apollo.thread.pool",
"128"));
+
+    public static final ThreadPoolExecutor INSTANCE = new ThreadPoolExecutor(POOL_SIZE, POOL_SIZE,
30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
         public Thread newThread(Runnable r) {
-            Thread rc = new Thread(r, "Apollo Worker");
+            Thread rc = new Thread(r, "Apollo Blocking Task");
             rc.setDaemon(true);
             return rc;
         }
     });
 
+    static {
+        INSTANCE.allowCoreThreadTimeOut(true);
+    }
+
 }



Mime
View raw message