Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Robin Puthli
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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:

OutputStream out = response.getOutputStream();

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,
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!