Andrzej
Andrzej

Reputation: 5127

ServletResponse.flushBuffer -- does it block until my response is delivered?

I am using Tomcat. The documentation for ServletResponse.flushBuffer says, "Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written." But I cannot figure out from this: will my doPost method be blocked on this function until the client successfully receives the response? In case of poor connection times, may ServletResponse.flushBuffer freeze the thread? Or is the delivery performed asynchronously?

My goal is to measure the time it takes for my client to see the response. I want to measure times just before and just after the call to flushBuffer, but I am not sure if this time covers all the process of delivering the message to the client's socket.

Regards, &rzej

Upvotes: 0

Views: 1418

Answers (1)

user207421
user207421

Reputation: 310956

will my servlet be blocked on this function until the client successfully receive the response?

No. The current thread will be blocked until the entire response has been written to the socket send buffer.

In case of poor connection times, may ServletResponse.flushBuffer freeze the servlet?

No, only the current thread.

Or is the delivery performed asynchronously?

Yes, but the response has to be buffered first, see above. If the buffer fills because the peer isn't reading or data hasn't been delivered and ACK'd, the writing thread will block until there is enough room.

Upvotes: 1

Related Questions