Differentiate synchronous and asynchronous error of an AIO operation
Alan Bateman
Alan.Bateman at oracle.com
Sat Jun 11 01:27:51 PDT 2011
Zhong Yu wrote:
> Greetings NIO team, kudos for your hard work and excellent results!
>
> I have a problem. I was very surprised by the fact that a completion
> handler may be invoked directly by the initiating thread. This is
> quite strange, and it's not trivial to write a thread safe handler to
> handle it properly. I think it would be much better that, if an IO
> operation completes immediately, the operation throws an exception,
> instead of invoking the handler directly.
>
>
I don't have time to reply to this now but just to say that I/O
operations can also completely successfully on the current thread. It
depends on the implementation of course but it's not just the error
case. There is an implementation specific property
(sun.nio.ch.maxCompletionHandlersOnStack) that may be useful as it can
be used to limit the number of completion handler frames on the stack.
Setting it to 1 will give you the behavior you are looking for.
-Alan.
More information about the nio-dev
mailing list