You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/06/27 21:15:21 UTC

svn commit: r1140276 - in /tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc: IOCSymbols.java services/TapestryIOCModule.java

Author: hlship
Date: Mon Jun 27 19:15:21 2011
New Revision: 1140276

URL: http://svn.apache.org/viewvc?rev=1140276&view=rev
Log:
TAP5-1563: Need configuration for queue size w/ ParallelExecutor; as is, limited to pool core size threads, rather than pool max size

Modified:
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCSymbols.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCSymbols.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCSymbols.java?rev=1140276&r1=1140275&r2=1140276&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCSymbols.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/IOCSymbols.java Mon Jun 27 19:15:21 2011
@@ -1,10 +1,10 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,24 +16,38 @@ package org.apache.tapestry5.ioc;
 
 /**
  * Configuration symbols used by the IoC container.
- *
+ * 
  * @since 5.2.2
  */
 public class IOCSymbols
 {
     /**
-     * The minimum size of the thread pool. The default is 3.
+     * The minimum size of the thread pool. The default is 3. When a task is created and there are fewer
+     * than this number of threads in the pool, a new thread is created for the task.
      */
     public static final String THREAD_POOL_CORE_SIZE = "tapestry.thread-pool.core-pool-size";
 
     /**
-     * Maximium size of the pool before submitted invocations must wait to execute; the default is 20.
+     * The size of the task queue. When there are at least {@linkplain #THREAD_POOL_CORE_SIZE the core number} of
+     * threads in the pool, tasks will be placed in the queue. If the queue is empty, more threads
+     * may be created (up to the {@linkplain #THREAD_POOL_MAX_SIZE maximum pool size}). If the queue is full and
+     * all threads have been created, the task is rejected.
+     * <p>
+     * The default is 100.
+     * 
+     * @since 5.3
+     * @see http://www.bigsoft.co.uk/blog/index.php/2009/11/27/rules-of-a-threadpoolexecutor-pool-size
+     */
+    public static final String THREAD_POOL_QUEUE_SIZE = "tapestry.thread-pool.queue-size";
+
+    /**
+     * Maximium size of the thread pool, which defaults to 10.
      */
     public static final String THREAD_POOL_MAX_SIZE = "tapestry.thread-pool.max-pool-size";
 
     /**
      * Time in milliseconds (via {@link org.apache.tapestry5.ioc.util.TimeInterval}) to keep waiting threads alive.
-     * Default is one minute (an epoch in application time).
+     * Default is one minute.
      */
     public static final String THREAD_POOL_KEEP_ALIVE = "tapestry.thread-pool.keep-alive";
 
@@ -41,7 +55,7 @@ public class IOCSymbols
      * By default, the {@link org.apache.tapestry5.ioc.services.ParallelExecutor} service uses a thread pool. In
      * environments (such as Google Application Engine) where thread creation is not allowed, this can be set to
      * "false", and deferred logic will, instead, execute immediately.
-     *
+     * 
      * @since 5.1.0.3
      */
     public static final String THREAD_POOL_ENABLED = "tapestry.thread-pool-enabled";

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=1140276&r1=1140275&r2=1140276&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java Mon Jun 27 19:15:21 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -524,6 +524,9 @@ public final class TapestryIOCModule
     @Symbol(IOCSymbols.THREAD_POOL_ENABLED)
     boolean threadPoolEnabled,
 
+    @Symbol(IOCSymbols.THREAD_POOL_QUEUE_SIZE)
+    int queueSize,
+
     PerthreadManager perthreadManager,
 
     RegistryShutdownHub shutdownHub,
@@ -534,8 +537,10 @@ public final class TapestryIOCModule
         if (!threadPoolEnabled)
             return new NonParallelExecutor();
 
+        LinkedBlockingQueue workQueue = new LinkedBlockingQueue(queueSize);
+
         final ThreadPoolExecutor executorService = new ThreadPoolExecutor(coreSize, maxSize, keepAliveMillis,
-                TimeUnit.MILLISECONDS, new LinkedBlockingQueue());
+                TimeUnit.MILLISECONDS, workQueue);
 
         shutdownHub.addRegistryShutdownListener(new RegistryShutdownListener()
         {
@@ -550,11 +555,12 @@ public final class TapestryIOCModule
 
     @Contribute(SymbolProvider.class)
     @FactoryDefaults
-    public static void setupDefaultSymbols(MappedConfiguration<String, String> configuration)
+    public static void setupDefaultSymbols(MappedConfiguration<String, Object> configuration)
     {
-        configuration.add(IOCSymbols.THREAD_POOL_CORE_SIZE, "3");
-        configuration.add(IOCSymbols.THREAD_POOL_MAX_SIZE, "20");
+        configuration.add(IOCSymbols.THREAD_POOL_CORE_SIZE, 3);
+        configuration.add(IOCSymbols.THREAD_POOL_MAX_SIZE, 20);
         configuration.add(IOCSymbols.THREAD_POOL_KEEP_ALIVE, "1 m");
-        configuration.add(IOCSymbols.THREAD_POOL_ENABLED, "true");
+        configuration.add(IOCSymbols.THREAD_POOL_ENABLED, true);
+        configuration.add(IOCSymbols.THREAD_POOL_QUEUE_SIZE, 100);
     }
 }