diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java index 8834c70cfa..01b11d519f 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java @@ -391,7 +391,12 @@ class NioProviderMetadata { if (loop != null) { loop.done = true; - executor.shutdownNow(); + try { + executor.shutdownNow(); + } catch (NullPointerException ex) { + // Some JDK throws NPE here, but shouldn't. + } + try { for (;;) { loop.selector.wakeup(); diff --git a/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java index 14e97d742d..a943c7acda 100644 --- a/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java +++ b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java @@ -32,13 +32,13 @@ import java.nio.channels.ServerSocketChannel; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelPipelineException; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.util.DummyHandler; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -62,16 +62,7 @@ public abstract class AbstractSocketClientBootstrapTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor); } protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); diff --git a/src/test/java/org/jboss/netty/bootstrap/AbstractSocketServerBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketServerBootstrapTest.java index 5c9a771390..8513f7adc6 100644 --- a/src/test/java/org/jboss/netty/bootstrap/AbstractSocketServerBootstrapTest.java +++ b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketServerBootstrapTest.java @@ -32,7 +32,6 @@ import java.net.Socket; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelException; @@ -45,6 +44,7 @@ import org.jboss.netty.channel.ChildChannelStateEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.channel.socket.SocketChannelConfig; import org.jboss.netty.util.DummyHandler; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -68,16 +68,7 @@ public abstract class AbstractSocketServerBootstrapTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor); } protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); diff --git a/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java b/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java index e2f19af483..9bc5f048b2 100644 --- a/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java +++ b/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java @@ -31,7 +31,6 @@ import java.util.Random; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jboss.netty.bootstrap.ClientBootstrap; @@ -47,6 +46,7 @@ import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -77,16 +77,7 @@ public abstract class AbstractSocketEchoTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor); } protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); diff --git a/src/test/java/org/jboss/netty/handler/codec/frame/AbstractSocketFixedLengthEchoTest.java b/src/test/java/org/jboss/netty/handler/codec/frame/AbstractSocketFixedLengthEchoTest.java index 1ae0a177f5..17fffab676 100644 --- a/src/test/java/org/jboss/netty/handler/codec/frame/AbstractSocketFixedLengthEchoTest.java +++ b/src/test/java/org/jboss/netty/handler/codec/frame/AbstractSocketFixedLengthEchoTest.java @@ -31,7 +31,6 @@ import java.util.Random; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jboss.netty.bootstrap.ClientBootstrap; @@ -47,6 +46,7 @@ import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -77,16 +77,7 @@ public abstract class AbstractSocketFixedLengthEchoTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor); } protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); diff --git a/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java index a9ad6235cd..ba2c02be39 100644 --- a/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java +++ b/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java @@ -31,7 +31,6 @@ import java.util.Random; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jboss.netty.bootstrap.ClientBootstrap; @@ -45,6 +44,7 @@ import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -83,16 +83,7 @@ public abstract class AbstractSocketCompatibleObjectStreamEchoTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor); } protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); diff --git a/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketObjectStreamEchoTest.java index 8927cbebfe..4942bd7885 100644 --- a/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketObjectStreamEchoTest.java +++ b/src/test/java/org/jboss/netty/handler/codec/serialization/AbstractSocketObjectStreamEchoTest.java @@ -31,7 +31,6 @@ import java.util.Random; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jboss.netty.bootstrap.ClientBootstrap; @@ -45,6 +44,7 @@ import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -83,16 +83,7 @@ public abstract class AbstractSocketObjectStreamEchoTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor); } protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); diff --git a/src/test/java/org/jboss/netty/handler/codec/string/AbstractSocketStringEchoTest.java b/src/test/java/org/jboss/netty/handler/codec/string/AbstractSocketStringEchoTest.java index 3c76b7c6af..18c6b8a019 100644 --- a/src/test/java/org/jboss/netty/handler/codec/string/AbstractSocketStringEchoTest.java +++ b/src/test/java/org/jboss/netty/handler/codec/string/AbstractSocketStringEchoTest.java @@ -31,7 +31,6 @@ import java.util.Random; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.jboss.netty.bootstrap.ClientBootstrap; @@ -47,6 +46,7 @@ import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; import org.jboss.netty.handler.codec.frame.Delimiters; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -85,16 +85,7 @@ public abstract class AbstractSocketStringEchoTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor); } protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); diff --git a/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java b/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java index dee3b3361d..d3f235c582 100644 --- a/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java +++ b/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java @@ -31,7 +31,6 @@ import java.util.Random; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import javax.net.ssl.SSLEngine; @@ -54,6 +53,7 @@ import org.jboss.netty.handler.execution.ExecutionHandler; import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor; import org.jboss.netty.logging.InternalLogger; import org.jboss.netty.logging.InternalLoggerFactory; +import org.jboss.netty.util.ExecutorShutdownUtil; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -88,26 +88,7 @@ public abstract class AbstractSocketSslEchoTest { @AfterClass public static void destroy() { - executor.shutdownNow(); - for (;;) { - try { - if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } - eventExecutor.shutdownNow(); - for (;;) { - try { - if (eventExecutor.awaitTermination(1, TimeUnit.MILLISECONDS)) { - break; - } - } catch (InterruptedException e) { - // Ignore. - } - } + ExecutorShutdownUtil.shutdown(executor, eventExecutor); } protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor);