7165762: (aio) Default thread pool should be configured so that threads terminated after a timeout period

Alan Bateman Alan.Bateman at oracle.com
Fri Nov 30 05:40:22 PST 2012

This is something that we discussed here back in April [1].

To re-cap, the thread pool for the default channel group is a cached 
thread pool where the threads don't terminate after an idle time. The 
reason for that is because of support for Windows editions that didn't 
support thread agnostic I/O (so we have to keep the threads alive, 
otherwise any I/O operations that they initiated would abort when the 
thread terminated). It was an oversight that this went into shared code 
to be used for all platforms (including newer version of Windows where 
this is not a concern).

As the older editions of Windows are dying out (Windows Server 2003 is 
now in extended support, long superseded by Windows Server 2008 and 
newer) then it's probably not worth refactoring this now and that the 
simplest thing is to just change it to use Executors.newCachedThreadPool 
so that all platforms get a thread pool where the threads to terminate 
after an idle time. The patch with the trivial change to do this is 

I've decided not to include a test case, mostly because it would take a 
long time (>1min) and also would be a bit fragile when with residual 
thread left behind by tests that were run previously in the same VM -- 
this is an issue that we've had in other areas where the thread count 
changes for reasons attributable to other tests.


diff --git a/src/share/classes/sun/nio/ch/ThreadPool.java 
--- a/src/share/classes/sun/nio/ch/ThreadPool.java
+++ b/src/share/classes/sun/nio/ch/ThreadPool.java
@@ -102,11 +102,7 @@ public class ThreadPool {
          if (threadFactory == null)
              threadFactory = defaultThreadFactory;
          // create thread pool
-        ExecutorService executor =
-            new ThreadPoolExecutor(0, Integer.MAX_VALUE,
-                                   Long.MAX_VALUE, TimeUnit.MILLISECONDS,
-                                   new SynchronousQueue<Runnable>(),
-                                   threadFactory);
+        ExecutorService executor = 
          return new ThreadPool(executor, false, initialSize);

[1] http://mail.openjdk.java.net/pipermail/nio-dev/2012-April/001629.html

More information about the nio-dev mailing list