permaculture playing cards*
The moose likes I/O and Streams and the fly likes ServletOutputStream is only closed when client has finished reading from it? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "ServletOutputStream is only closed when client has finished reading from it?" Watch "ServletOutputStream is only closed when client has finished reading from it?" New topic
Author

ServletOutputStream is only closed when client has finished reading from it?

Robin Puthli
Greenhorn

Joined: Feb 03, 2005
Posts: 1
Hi,

I am working on a performance measurement tool and need to measure how long a client needs to download data from a servlet. I was doing this from a client, but ran into curious behaviour with ServletOutputStream.

The server response is put into a ByteArrayOutputStream (outBuffer) and then written to the ServletOutputStream like this:

log("Starting");
OutputStream out = response.getOutputStream();
out.write(outBuffer.toByteArray());
out.flush();
out.close();
log("Done");

I always assumed that the response would be buffered somewhere in the servlet environment so that the servlet would not be blocked by a slow client. However the log("Done") statement is only reached when the client is finished reading. I can step through the client and the servlet will wait obediently (until some timeout is reached). The servlet is running on Tomcat 5.5.

Q1. Can i assume that when the log("Done") statement is reached the client has read all of the data in the response and has closed the connection?

Q2. Can anyone point me to some documentation on how a ServletOutputStream works exactly. The javadoc details the client side or the server side, but not what is going on while both are exchanging data.


Thanks in advance,
Robin
 
 
subject: ServletOutputStream is only closed when client has finished reading from it?