executor for AsynchronousFileChannel.open()

Alan Bateman Alan.Bateman at oracle.com
Tue Apr 10 03:15:37 PDT 2012


On 02/04/2012 22:41, Zhong Yu wrote:
> :
> Let's say my completion handlers do nothing but compute checksums of
> file content. In that case, can I use a ThreadPoolExecutor with
> maximumPoolSize == Runtime.availableProcessors()? Is there any
> assurance that no other tasks will be submitted to this executor?
The reason for the wording in the open method is to allow for highly 
varied implementations. For example, on Windows XP you may observe tasks 
being submitted to the thread pool to initiate I/O operations for cases 
where you attempt to initiate on non-pooled thread. On newer versions of 
Windows you don't observe this and you will only see tasks that are 
handling completion events and invoking your completion handlers. On 
Solaris/Linux/Mac then the default implementation of 
AsynchronousFileChannel isn't making direct use of kernel facilities at 
this time so you will observe tasks that last for the duration of the 
I/O operation. Hopefully it should start to become clear that it's not 
easy to provide general advice on the maximum pool size. You suggestion 
to start with Runtime.availableProcessors should be okay but I would 
suggest monitoring it to see how much concurrency you actually get. It 
may be that the I/O is too slow compared to the checksum computation, in 
which case you may not observe too many threads executing completion 
handlers concurrently.

-Alan.


More information about the nio-dev mailing list