- Further sync the two endpoints.
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 23 Apr 2006 21:37:32 +0000 (21:37 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 23 Apr 2006 21:37:32 +0000 (21:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@396324 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/AprEndpoint.java
java/org/apache/tomcat/util/net/JIoEndpoint.java

index ed26b78..4b34802 100644 (file)
@@ -698,7 +698,7 @@ public class AprEndpoint {
                 workers = new WorkerStack(maxThreads);\r
             }\r
 \r
-            // Start acceptor thread\r
+            // Start acceptor threads\r
             for (int i = 0; i < acceptorThreadCount; i++) {\r
                 Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);\r
                 acceptorThread.setPriority(threadPriority);\r
@@ -706,7 +706,7 @@ public class AprEndpoint {
                 acceptorThread.start();\r
             }\r
 \r
-            // Start poller thread\r
+            // Start poller threads\r
             pollers = new Poller[pollerThreadCount];\r
             for (int i = 0; i < pollerThreadCount; i++) {\r
                 pollers[i] = new Poller();\r
@@ -717,7 +717,7 @@ public class AprEndpoint {
                 pollerThread.start();\r
             }\r
 \r
-            // Start sendfile thread\r
+            // Start sendfile threads\r
             if (useSendfile) {\r
                 sendfiles = new Sendfile[sendfileThreadCount];\r
                 for (int i = 0; i < sendfileThreadCount; i++) {\r
@@ -1369,12 +1369,12 @@ public class AprEndpoint {
         protected long sendfilePollset = 0;\r
         protected long pool = 0;\r
         protected long[] desc;\r
-        protected HashMap sendfileData;\r
+        protected HashMap<Long, SendfileData> sendfileData;\r
         \r
         protected int sendfileCount;\r
         public int getSendfileCount() { return sendfileCount; }\r
 \r
-        protected ArrayList addS;\r
+        protected ArrayList<SendfileData> addS;\r
 \r
         /**\r
          * Create the sendfile poller. With some versions of APR, the maximum poller size will\r
@@ -1393,8 +1393,8 @@ public class AprEndpoint {
                 sendfilePollset = allocatePoller(size, pool, soTimeout);\r
             }\r
             desc = new long[size * 2];\r
-            sendfileData = new HashMap(size);\r
-            addS = new ArrayList();\r
+            sendfileData = new HashMap<Long, SendfileData>(size);\r
+            addS = new ArrayList<SendfileData>();\r
         }\r
 \r
         /**\r
@@ -1403,7 +1403,7 @@ public class AprEndpoint {
         protected void destroy() {\r
             // Close any socket remaining in the add queue\r
             for (int i = (addS.size() - 1); i >= 0; i--) {\r
-                SendfileData data = (SendfileData) addS.get(i);\r
+                SendfileData data = addS.get(i);\r
                 Socket.destroy(data.socket);\r
             }\r
             // Close all sockets still in the poller\r
@@ -1520,7 +1520,7 @@ public class AprEndpoint {
                     if (addS.size() > 0) {\r
                         synchronized (this) {\r
                             for (int i = (addS.size() - 1); i >= 0; i--) {\r
-                                SendfileData data = (SendfileData) addS.get(i);\r
+                                SendfileData data = addS.get(i);\r
                                 int rv = Poll.add(sendfilePollset, data.socket, Poll.APR_POLLOUT);\r
                                 if (rv == Status.APR_SUCCESS) {\r
                                     sendfileData.put(new Long(data.socket), data);\r
@@ -1540,7 +1540,7 @@ public class AprEndpoint {
                         for (int n = 0; n < rv; n++) {\r
                             // Get the sendfile state\r
                             SendfileData state =\r
-                                (SendfileData) sendfileData.get(new Long(desc[n*2+1]));\r
+                                sendfileData.get(new Long(desc[n*2+1]));\r
                             // Problem events\r
                             if (((desc[n*2] & Poll.APR_POLLHUP) == Poll.APR_POLLHUP)\r
                                     || ((desc[n*2] & Poll.APR_POLLERR) == Poll.APR_POLLERR)) {\r
index f783d5d..00cee8a 100644 (file)
@@ -60,12 +60,6 @@ public class JIoEndpoint {
 
 
     /**
-     * The acceptor thread.
-     */
-    protected Thread acceptorThread = null;
-
-
-    /**
      * Available workers.
      */
     protected WorkerStack workers = null;
@@ -117,6 +111,14 @@ public class JIoEndpoint {
 
 
     /**
+     * Acceptor thread count.
+     */
+    protected int acceptorThreadCount = 0;
+    public void setAcceptorThreadCount(int acceptorThreadCount) { this.acceptorThreadCount = acceptorThreadCount; }
+    public int getAcceptorThreadCount() { return acceptorThreadCount; }
+
+
+    /**
      * External Executor based thread pool.
      */
     protected Executor executor = null;
@@ -291,6 +293,7 @@ public class JIoEndpoint {
                         try {
                             socket.close();
                         } catch (IOException e) {
+                            // Ignore
                         }
                     }
                 } catch (Throwable t) {
@@ -450,7 +453,16 @@ public class JIoEndpoint {
 
     // -------------------- Public methods --------------------
 
-    public void init() throws IOException, InstantiationException {
+    public void init()
+        throws Exception {
+
+        if (initialized)
+            return;
+        
+        // Initialize thread count defaults for acceptor
+        if (acceptorThreadCount == 0) {
+            acceptorThreadCount = 1;
+        }
         if (serverSocketFactory == null) {
             serverSocketFactory = ServerSocketFactory.getDefault();
         }
@@ -467,7 +479,9 @@ public class JIoEndpoint {
         }
         //if( serverTimeout >= 0 )
         //    serverSocket.setSoTimeout( serverTimeout );
+        
         initialized = true;
+        
     }
     
     public void start()
@@ -485,11 +499,13 @@ public class JIoEndpoint {
                 workers = new WorkerStack(maxThreads);
             }
 
-            // Start acceptor thread
-            acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor");
-            acceptorThread.setPriority(threadPriority);
-            acceptorThread.setDaemon(daemon);
-            acceptorThread.start();
+            // Start acceptor threads
+            for (int i = 0; i < acceptorThreadCount; i++) {
+                Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i);
+                acceptorThread.setPriority(threadPriority);
+                acceptorThread.setDaemon(daemon);
+                acceptorThread.start();
+            }
         }
     }
 
@@ -510,7 +526,6 @@ public class JIoEndpoint {
         if (running) {
             running = false;
             unlockAccept();
-            acceptorThread = null;
         }
     }