Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jetty-9.1 -- ServletOutputStream.isReady() -- how much data can be written without blocking?




On 12 September 2013 06:48, Richard Johnson <johnson.richard78@xxxxxxxxx> wrote:
 
but it is unclear how much data can be written without blocking.


If isReady() returns true, you can write as much data as you like in a single write call and it will not block.

I think some impls achieve this by copying the data (Yuck OOME here we come!!!), but jetty just keeps a reference to the passed byte array and essentially owns it until the write is complete (signalled with a callback or subsequent isReady()==true).

 
  I.e. if we do large enough write in subsequent out.writ(buffer, 0, len), it would block? Or not?

If a subsequent write occurs whilst the previous one is not complete, then you will get a PendingWriteException.  Actually you might even get that if you do a write without calling isReady().

Spec is indeed unclear on this point and there was talk about going to autoblocking mode if a write was done without calling isReady().... but then there is no way of knowing when you can do that write and avoid a WritePendingException unless you call isReady(), in which case you are async.

Short story is that you must call isReady() before any subsequent writes after an onWritePossible callback.


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

Back to the top