jsr340-experts@servlet-spec.java.net

[jsr340-experts] Re: [servlet-spec users] Re: Re: Re: NIO specification clarification

From: Greg Wilkins <gregw_at_intalio.com>
Date: Tue, 14 May 2013 17:32:52 +1000

On 1 May 2013 00:33, Rémy Maucherat <rmaucher_at_redhat.com> wrote:

> My question with auto blocking is how does the Servlet container know if a
>> read or write is meant to be blocking or not? The user code (the WebSocket
>> implementation) knows but there is no API that enables it to tell the
>> container. I had originally thought that flush() could be used to do this
>> (i.e. block if flush() is called) but as you pointed out, that might work
>> in an HTTP upgrade scenario but not in a Servlet one. Using flush(0 in this
>> way would work for WebSocket since it used HTTp upgrade but having the same
>> method behave differently for HTYTP Upgrade and async servlets doesn't seem
>> right either.
>>
> It should be possible to make the decision about blocking or not by using
> isReady. If isReady is used when doing the reads/writes, it will not block.
> If isReady is not used, and things occurs inside a container thread, it
> blocks (I never thought it would be a good idea to block an async thread).


This is a good point and related to the questions Mark asked on the other
thread.

I think that blocking an async thread is definitely a bad idea, thus I
favour throwing Read/Write pending exceptions when multiple operations are
attempted, rather than have the subsequent operations 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.