The following test program does a simple bind/accept and then shuts down the channel group.
I would expect the program to print out the resulting ShutdownChannelGroupException, but instead it never calls the completion handler and throws the exception on the thread pool.
Can someone shed some light on whats going on? Am I misinterpreting the docs when they say shutdownNow() has the following behavior: "The group terminates when all actively executing completion handlers have run to completion and all resources have been released".
Is it that the callback isn't 'active' yet and therefore just gets discarded?
public static void main(String[] args) throws java.io.IOException, InterruptedException {
ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
AsynchronousChannelGroup group = AsynchronousChannelGroup.withThreadPool(service);
AsynchronousServerSocketChannel acceptor = AsynchronousServerSocketChannel.open(group);
acceptor.bind(new InetSocketAddress(50000));
acceptor.accept(null, new CompletionHandler<AsynchronousSocketChannel, Object>() {
@Override
public void completed(AsynchronousSocketChannel result, Object attachment) {
}
@Override
public void failed(Throwable exc, Object attachment) {
System.out.println("failed: " + exc.getMessage());
}
});
System.out.println("Shutting down");
group.shutdownNow();
System.out.println("Awaiting termination");
group.awaitTermination(60, TimeUnit.SECONDS);
System.out.println("Sleeping");
Thread.sleep(1000);
}