executor for AsynchronousFileChannel.open()
Alan Bateman
Alan.Bateman at oracle.com
Sun Apr 1 12:44:31 PDT 2012
On 31/03/2012 06:02, Zhong Yu wrote:
> Hi there,
>
> Suppose I have 100 asyn file channels for reading (concurrently). All
> my completion handlers are non-blocking and short. What kind of
> executor is best for AsynchronousFileChannel.open()?
>
> My initial choice was a ThreadPoolExecutor with maximumPoolSize==P
> where P is the number of processors, because it would be less
> efficient to have more than P threads executing non-blocking tasks
> (i.e. completion handlers).
>
> However the javadoc of AsynchronousFileChannel.open() states that
> there could be other kinds of tasks submitted to the executor, and the
> nature of these tasks are unclear. Then I'm lost.
>
> Any advice on an appropriate executor for my specific use case?
>
> Thanks,
> Zhong Yu
For compute tasks then a function of the number of cores or hardware
threads is usually appropriate but for I/O operations then it's a lot
more difficult to size the thread pool. It's possible that things may be
dominated by file I/O and that may limit the number of completion
handlers that you see running concurrently. The only I will say is that
this is really 100 distinct AsynchronousFileChannel instances then you
may wish to share a thread pool between them, especially if there is
only 1 or a small number of concurrent I/O operations on each file.
-Alan.
More information about the nio-dev
mailing list