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}