Differentiate synchronous and asynchronous error of an AIO operation

Zhong Yu zhong.j.yu at gmail.com
Tue Jun 14 08:05:15 PDT 2011


On Tue, Jun 14, 2011 at 2:50 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> We have a page with some implementation details [1] that may be useful to
> this discussion. With a fixed thread pool then the tasks execute a loop that
> dequeue events and dispatch directly to the completion handler.  These are
> long running tasks with no hand-off per I/O operation. When not using a
> fixed thread pool then it works a bit like what you are suggesting. A small
> pool of internal threads handles the I/O events then executes tasks that
> invoke the completion handler (so a task per I/O operation). The issue with

That means the user provided executor service will only be used for
completion handlers? That's great. However this is not guaranteed by
the javadoc, which actually hints otherwise:

http://download.java.net/jdk7/docs/api/java/nio/channels/AsynchronousChannelGroup.html

"In addition to handling I/O events, the pooled threads may also
execute other tasks required to support the execution of asynchronous
I/O operations."

Should the javadoc be clear in that the user provided executor service
will *not* be used for such "other tasks"?

> calling the completion handler directly is that you will call it on an
> internal thread and so it won't have the expected identity. Also the size of

The little trick I described requires that the executor and the
handlers cooperate. The responsibility of switching thread is moved
from the executor to the handlers, and the handlers must switch thread
immediately. However since the handlers have more information about
tasks, they can do smarter threading, e.g. dispatch all tasks of the
same channel to the same thread. The executor doesn't have such
knowledge about tasks, which all look the same the the executor.

- Zhong Yu


More information about the nio-dev mailing list