Hi
I am investigating, how I can archive asynchronous writes with tomcat.
For servlets I came up with code like this:
final AsyncContext context = request.startAsync();
final ServletInputStream input = request.getInputStream();
final ServletOutputStream output = response.getOutputStream();
ChannelProcessor processor = new ChannelProcessor( channel, input,
output );
context.addListener( processor );
input.setReadListener( processor );
output.setWriteListener( processor );
While ChannelProcessor is my class that implements (beside others)
WriteListener, so I get notified, when the ServletOutputStream is ready to send
more data.
However, looking at the code, I suspect that "output.write( byte[] buffer )"
will still block, if the amount of data in buffer is larger than the maximum
size of the OutputBuffer used by that connection:
Call stack:
CoyoteOutputStream.write (is ServletOutputStream.write)
OutputBuffer.write
ByteChunk.append
ByteChunk.flushBuffer
OutputBuffer.realWriteBytes
... from here on I am not sure.
For WebSockets there is
session.getAsyncRemote().sendBinary( buffer, handkler );
But that calls ServletOutputStream.write (maybe from another thread)
So, are these really asynchronous?
Is a call to ServletOutputStream.write always guaranteed to return without
blocking?`
Where is that implemented?
Regards,
Steffen
smime.p7s
Description: S/MIME cryptographic signature
