From: remm Date: Sun, 23 Apr 2006 21:37:32 +0000 (+0000) Subject: - Further sync the two endpoints. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ab5c4164046ec0f465c8c6b0409907430f7e49d0;p=tomcat7.0 - Further sync the two endpoints. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@396324 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index ed26b7840..4b34802f8 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -698,7 +698,7 @@ public class AprEndpoint { workers = new WorkerStack(maxThreads); } - // Start acceptor thread + // Start acceptor threads for (int i = 0; i < acceptorThreadCount; i++) { Thread acceptorThread = new Thread(new Acceptor(), getName() + "-Acceptor-" + i); acceptorThread.setPriority(threadPriority); @@ -706,7 +706,7 @@ public class AprEndpoint { acceptorThread.start(); } - // Start poller thread + // Start poller threads pollers = new Poller[pollerThreadCount]; for (int i = 0; i < pollerThreadCount; i++) { pollers[i] = new Poller(); @@ -717,7 +717,7 @@ public class AprEndpoint { pollerThread.start(); } - // Start sendfile thread + // Start sendfile threads if (useSendfile) { sendfiles = new Sendfile[sendfileThreadCount]; for (int i = 0; i < sendfileThreadCount; i++) { @@ -1369,12 +1369,12 @@ public class AprEndpoint { protected long sendfilePollset = 0; protected long pool = 0; protected long[] desc; - protected HashMap sendfileData; + protected HashMap sendfileData; protected int sendfileCount; public int getSendfileCount() { return sendfileCount; } - protected ArrayList addS; + protected ArrayList addS; /** * Create the sendfile poller. With some versions of APR, the maximum poller size will @@ -1393,8 +1393,8 @@ public class AprEndpoint { sendfilePollset = allocatePoller(size, pool, soTimeout); } desc = new long[size * 2]; - sendfileData = new HashMap(size); - addS = new ArrayList(); + sendfileData = new HashMap(size); + addS = new ArrayList(); } /** @@ -1403,7 +1403,7 @@ public class AprEndpoint { protected void destroy() { // Close any socket remaining in the add queue for (int i = (addS.size() - 1); i >= 0; i--) { - SendfileData data = (SendfileData) addS.get(i); + SendfileData data = addS.get(i); Socket.destroy(data.socket); } // Close all sockets still in the poller @@ -1520,7 +1520,7 @@ public class AprEndpoint { if (addS.size() > 0) { synchronized (this) { for (int i = (addS.size() - 1); i >= 0; i--) { - SendfileData data = (SendfileData) addS.get(i); + SendfileData data = addS.get(i); int rv = Poll.add(sendfilePollset, data.socket, Poll.APR_POLLOUT); if (rv == Status.APR_SUCCESS) { sendfileData.put(new Long(data.socket), data); @@ -1540,7 +1540,7 @@ public class AprEndpoint { for (int n = 0; n < rv; n++) { // Get the sendfile state SendfileData state = - (SendfileData) sendfileData.get(new Long(desc[n*2+1])); + sendfileData.get(new Long(desc[n*2+1])); // Problem events if (((desc[n*2] & Poll.APR_POLLHUP) == Poll.APR_POLLHUP) || ((desc[n*2] & Poll.APR_POLLERR) == Poll.APR_POLLERR)) { diff --git a/java/org/apache/tomcat/util/net/JIoEndpoint.java b/java/org/apache/tomcat/util/net/JIoEndpoint.java index f783d5dd9..00cee8a57 100644 --- a/java/org/apache/tomcat/util/net/JIoEndpoint.java +++ b/java/org/apache/tomcat/util/net/JIoEndpoint.java @@ -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; } }