jsr340-experts@servlet-spec.java.net

[jsr340-experts] setWriteListener setReadListener

From: Greg Wilkins <gregw_at_intalio.com>
Date: Fri, 17 May 2013 13:54:56 +1000

I'm belatedly getting stuck into our implementation of non blocking IO and
have a few things that I'd like to see clearer in the spec.

Consider the following code:

   request.startAsync();
   response.getOutputStream().setWriteListener(myListener);
   request.getInputStream().setReadListener(myListener);
   return;


The javadoc tells us that the listener will be called back as soon as it is
possible to read/write and in most circumstances this will be
immediately.

Is it an acceptable implementation to have the thread that called the set
listener methods immediately call back the listeners from within the scope
of the set call?
If not, then I'd prefer to avoid dispatching another thread for this and
instead use the thread that was dispatched to the servlet to call the
listeners after it returns to the container. So is it OK to defer the call
back until after that return or does that contravene the "as soon as it is
possible"?

Then I believe that we wish to have only a single thread dispatched to the
request at a time, so we should not call the read listener methods in
parallel to the write listener methods. So if both are ready, which one
should we call first? As we are a server, I assume we should try reading
before we try writing?

Note that because we are only 1 thread per request, it is really important
that we do not let multiple calls to read/write block, as we could end up
deadlocking ourselves with large content. So as per my previous message, we
should throw read/write pending exceptions rather than block.

cheers



-- 
Greg Wilkins <gregw_at_intalio.com>
http://www.webtide.com
Developer advice and support from the Jetty & CometD experts.
Intalio, the modern way to build business applications.