executor for AsynchronousFileChannel.open()
Zhong Yu
zhong.j.yu at gmail.com
Mon Apr 2 14:41:14 PDT 2012
On Sun, Apr 1, 2012 at 2:44 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 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
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?
> 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.
Yes, a file channel is only read by one thread at any time, no
concurrent activities; I intend to have all file channels share 1
executor, but not sure what kind of executor is good for the purpose.
I know exactly the nature of my completion handlers, but I don't know
if other tasks could be submitted to the executor.
More information about the nio-dev
mailing list