JBossWeb SVN: r2399 - branches/7.4.x/src/main/java/org/apache/tomcat/util/net.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-04-07 14:40:52 -0400 (Mon, 07 Apr 2014)
New Revision: 2399
Modified:
branches/7.4.x/src/main/java/org/apache/tomcat/util/net/Constants.java
branches/7.4.x/src/main/java/org/apache/tomcat/util/net/DefaultNioServerSocketChannelFactory.java
branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioServerSocketChannelFactory.java
Log:
BZ1075695: Try some cleaner thread group shutdown, if possible.
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/util/net/Constants.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/util/net/Constants.java 2014-04-01 14:00:05 UTC (rev 2398)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/util/net/Constants.java 2014-04-07 18:40:52 UTC (rev 2399)
@@ -39,6 +39,9 @@
public static final int SO_SND_BUFFER =
Integer.valueOf(System.getProperty("org.apache.tomcat.util.net.SO_SND_BUFFER", "-1")).intValue();
+ public static final int SHUTDOWN_TIMEOUT =
+ Integer.valueOf(System.getProperty("org.apache.tomcat.util.net.SHUTDOWN_TIMEOUT", "5000")).intValue();
+
/**
* The Request attribute key for the cipher suite.
*/
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/util/net/DefaultNioServerSocketChannelFactory.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/util/net/DefaultNioServerSocketChannelFactory.java 2014-04-01 14:00:05 UTC (rev 2398)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/util/net/DefaultNioServerSocketChannelFactory.java 2014-04-07 18:40:52 UTC (rev 2399)
@@ -24,6 +24,7 @@
import java.net.StandardSocketOptions;
import java.nio.channels.AsynchronousChannelGroup;
import java.nio.channels.AsynchronousServerSocketChannel;
+import java.util.concurrent.TimeUnit;
/**
* {@code DefaultNioServerSocketChannelFactory}
@@ -66,9 +67,23 @@
* @see org.apache.tomcat.util.net.NioServerSocketChannelFactory#destroy()
*/
public void destroy() throws IOException {
- this.threadGroup = null;
- this.attributes.clear();
- this.attributes = null;
+ try {
+ if (threadGroup != null && internalExecutor) {
+ threadGroup.shutdownNow();
+ long timeout = Constants.SHUTDOWN_TIMEOUT;
+ if (timeout > 0) {
+ try {
+ threadGroup.awaitTermination(timeout, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ }
+ } finally {
+ this.threadGroup = null;
+ this.attributes.clear();
+ this.attributes = null;
+ }
}
/*
@@ -103,7 +118,8 @@
*/
@Override
public AsynchronousServerSocketChannel createServerChannel(int port, int backlog,
- InetAddress ifAddress, boolean reuseAddress) throws IOException {
+ InetAddress ifAddress, boolean reuseAddress, boolean internalExecutor) throws IOException {
+ this.internalExecutor = internalExecutor;
return open().setOption(StandardSocketOptions.SO_REUSEADDR, reuseAddress).bind(
new InetSocketAddress(ifAddress, port), backlog);
}
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java 2014-04-01 14:00:05 UTC (rev 2398)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java 2014-04-07 18:40:52 UTC (rev 2399)
@@ -212,7 +212,7 @@
if (listener == null) {
listener = this.serverSocketChannelFactory.createServerChannel(port, backlog,
- address, reuseAddress);
+ address, reuseAddress, internalExecutor);
}
initialized = true;
Modified: branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioServerSocketChannelFactory.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioServerSocketChannelFactory.java 2014-04-01 14:00:05 UTC (rev 2398)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioServerSocketChannelFactory.java 2014-04-07 18:40:52 UTC (rev 2399)
@@ -39,6 +39,7 @@
protected Hashtable<String, Object> attributes = new Hashtable<String, Object>();
protected AsynchronousChannelGroup threadGroup;
+ protected boolean internalExecutor = true;
/**
* Create a new instance of {@code NioServerSocketChannelFactory}
@@ -188,7 +189,7 @@
*/
public AsynchronousServerSocketChannel createServerChannel(int port, int backlog)
throws IOException {
- return createServerChannel(port, backlog, null, false);
+ return createServerChannel(port, backlog, null, false, true);
}
/**
@@ -210,7 +211,7 @@
* for networking errors
*/
public abstract AsynchronousServerSocketChannel createServerChannel(int port, int backlog,
- InetAddress ifAddress, boolean reuseAddress) throws IOException;
+ InetAddress ifAddress, boolean reuseAddress, boolean internalExecutor) throws IOException;
/**
* Initialize the specified {@code NioChannel}
10 years, 9 months
JBossWeb SVN: r2398 - branches/7.4.x/src/main/java/org/apache/coyote/http11.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2014-04-01 10:00:05 -0400 (Tue, 01 Apr 2014)
New Revision: 2398
Modified:
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
Log:
GTNPORTAL-3435: Clear the buffer since its state should be the same as the other buffer, but no need to clear it on recycle.
Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprOutputBuffer.java 2014-03-24 09:19:51 UTC (rev 2397)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalAprOutputBuffer.java 2014-04-01 14:00:05 UTC (rev 2398)
@@ -320,7 +320,6 @@
// Recycle Request object
response.recycle();
- bbuf.clear();
socket = 0;
pos = 0;
@@ -570,6 +569,7 @@
if (pos > 0) {
// Sending the response header buffer
+ bbuf.clear();
bbuf.put(buf, 0, pos);
}
Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java 2014-03-24 09:19:51 UTC (rev 2397)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java 2014-04-01 14:00:05 UTC (rev 2398)
@@ -359,8 +359,7 @@
}
}
response.setLastWrite(res);
- // bbuf.clear();
- clearBuffer();
+ bbuf.clear();
if (res < 0) {
throw new IOException(MESSAGES.failedWrite());
@@ -467,12 +466,6 @@
flushBuffer();
}
- /**
- *
- */
- protected void clearBuffer() {
- this.bbuf.clear();
- }
/**
* Recycle this object
@@ -481,7 +474,6 @@
channel = null;
// Recycle Request object
response.recycle();
- this.clearBuffer();
pos = 0;
lastActiveFilter = -1;
committed = false;
@@ -666,6 +658,7 @@
if (pos > 0) {
// Sending the response header buffer
+ bbuf.clear();
bbuf.put(buf, 0, pos);
}
}
10 years, 9 months