Author: markt
Date: Fri Nov 21 07:46:12 2008
New Revision: 719602

URL: http://svn.apache.org/viewvc?rev=719602&view=rev
Log:
Make size of all threads pools dynamically configurable

Modified:
    tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java?rev=719602&r1=719601&r2=719602&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java Fri 
Nov 21 07:46:12 2008
@@ -130,14 +130,23 @@
 
     public void setMaxIdleTime(int maxIdleTime) {
         this.maxIdleTime = maxIdleTime;
+        if (executor != null) {
+            executor.setKeepAliveTime(maxIdleTime, TimeUnit.MILLISECONDS);
+        }
     }
 
     public void setMaxThreads(int maxThreads) {
         this.maxThreads = maxThreads;
+        if (executor != null) {
+            executor.setMaximumPoolSize(maxThreads);
+        }
     }
 
     public void setMinSpareThreads(int minSpareThreads) {
         this.minSpareThreads = minSpareThreads;
+        if (executor != null) {
+            executor.setCorePoolSize(minSpareThreads);
+        }
     }
 
     public void setName(String name) {

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=719602&r1=719601&r2=719602&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Fri Nov 21 
07:46:12 2008
@@ -36,6 +36,7 @@
 import org.apache.tomcat.jni.SSLSocket;
 import org.apache.tomcat.jni.Socket;
 import org.apache.tomcat.jni.Status;
+import org.apache.tomcat.util.net.JIoEndpoint.Worker;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -179,7 +180,14 @@
      * Maximum amount of worker threads.
      */
     protected int maxThreads = 200;
-    public void setMaxThreads(int maxThreads) { this.maxThreads = maxThreads; }
+    public void setMaxThreads(int maxThreads) {
+        this.maxThreads = maxThreads;
+        if (running) {
+            synchronized(workers) {
+                workers.resize(maxThreads);
+            }
+        }
+    }
     public int getMaxThreads() { return maxThreads; }
 
 
@@ -1883,12 +1891,18 @@
         }
         
         /** 
-         * Put the object into the queue.
+         * Put the object into the queue. If the queue is full (for example if
+         * the queue has been reduced in size) the object will be dropped.
          * 
-         * @param   object      the object to be appended to the queue (first 
element). 
+         * @param   object  the object to be appended to the queue (first
+         *                  element).
          */
         public void push(Worker worker) {
-            workers[end++] = worker;
+            if (end < workers.length) {
+                workers[end++] = worker;
+            } else {
+                curThreads--;
+            }
         }
         
         /**
@@ -1923,6 +1937,22 @@
         public int size() {
             return (end);
         }
+        
+        /**
+         * Resize the queue. If there are too many objects in the queue for the
+         * new size, drop the excess.
+         * 
+         * @param newSize
+         */
+        public void resize(int newSize) {
+            Worker[] newWorkers = new Worker[newSize];
+            int len = workers.length;
+            if (newSize < len) {
+                len = newSize;
+            }
+            System.arraycopy(workers, 0, newWorkers, 0, len);
+            workers = newWorkers;
+        }
     }
 
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=719602&r1=719601&r2=719602&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Fri Nov 21 
07:46:12 2008
@@ -174,7 +174,14 @@
      * Maximum amount of worker threads.
      */
     protected int maxThreads = 200;
-    public void setMaxThreads(int maxThreads) { this.maxThreads = maxThreads; }
+    public void setMaxThreads(int maxThreads) {
+        this.maxThreads = maxThreads;
+        if (running) {
+            synchronized(workers) {
+                workers.resize(maxThreads);
+            }
+        }
+    }
     public int getMaxThreads() { return maxThreads; }
 
 
@@ -777,12 +784,18 @@
         }
         
         /** 
-         * Put the object into the queue.
+         * Put the object into the queue. If the queue is full (for example if
+         * the queue has been reduced in size) the object will be dropped.
          * 
-         * @param   object      the object to be appended to the queue (first 
element). 
+         * @param   object  the object to be appended to the queue (first
+         *                  element).
          */
         public void push(Worker worker) {
-            workers[end++] = worker;
+            if (end < workers.length) {
+                workers[end++] = worker;
+            } else {
+                curThreads--;
+            }
         }
         
         /**
@@ -817,6 +830,22 @@
         public int size() {
             return (end);
         }
+        
+        /**
+         * Resize the queue. If there are too many objects in the queue for the
+         * new size, drop the excess.
+         * 
+         * @param newSize
+         */
+        public void resize(int newSize) {
+            Worker[] newWorkers = new Worker[newSize];
+            int len = workers.length;
+            if (newSize < len) {
+                len = newSize;
+            }
+            System.arraycopy(workers, 0, newWorkers, 0, len);
+            workers = newWorkers;
+        }
     }
 
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=719602&r1=719601&r2=719602&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri Nov 21 
07:46:12 2008
@@ -52,6 +52,7 @@
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.IntrospectionUtils;
+import org.apache.tomcat.util.net.JIoEndpoint.Worker;
 import org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -350,7 +351,14 @@
      * Maximum amount of worker threads.
      */
     protected int maxThreads = 200;
-    public void setMaxThreads(int maxThreads) { this.maxThreads = maxThreads; }
+    public void setMaxThreads(int maxThreads) {
+        this.maxThreads = maxThreads;
+        if (running) {
+            synchronized(workers) {
+                workers.resize(maxThreads);
+            }
+        }
+    }
     public int getMaxThreads() { return maxThreads; }
 
 
@@ -2026,12 +2034,18 @@
         }
 
         /** 
-         * Put the object into the queue.
+         * Put the object into the queue. If the queue is full (for example if
+         * the queue has been reduced in size) the object will be dropped.
          * 
-         * @param   object      the object to be appended to the queue (first 
element). 
+         * @param   object  the object to be appended to the queue (first
+         *                  element).
          */
         public void push(Worker worker) {
-            workers[end++] = worker;
+            if (end < workers.length) {
+                workers[end++] = worker;
+            } else {
+                curThreads--;
+            }
         }
 
         /**
@@ -2066,6 +2080,22 @@
         public int size() {
             return (end);
         }
+        
+        /**
+         * Resize the queue. If there are too many objects in the queue for the
+         * new size, drop the excess.
+         * 
+         * @param newSize
+         */
+        public void resize(int newSize) {
+            Worker[] newWorkers = new Worker[newSize];
+            int len = workers.length;
+            if (newSize < len) {
+                len = newSize;
+            }
+            System.arraycopy(workers, 0, newWorkers, 0, len);
+            workers = newWorkers;
+        }
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to