Two Laptop Bag
The moose likes Servlets and the fly likes Catch Error After Response Sent? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Catch Error After Response Sent?" Watch "Catch Error After Response Sent?" New topic

Catch Error After Response Sent?

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
A colleague and I recently had the following discussion.

A servlet gets a request, completes it's processing, completes the service method and then there is a network error. For example, the servlet does seven or eight large DB operations that takes a total of about 5 seconds, during that five seconds somebody kicks out the network connection on the App server. He said that the servlet could then catch the error and we'd be able to log the information that the client never got the response.

I said that it wasn't possible since the service method would still complete and then try and send out response...and that it would never know that there was a network error and that client didn't get the response.

Who is correct?
Ryan Muster

Joined: Nov 11, 2007
Posts: 18
Ha ha... nice.

He's right but I think you right too

TCP is a guarenteed protocol, so the second you screw that connection around, if the buffer has not cleared and socket loses the connection it will throw an exception...
If it was UDP you would be right.

... but on a servlet container like Tomcat I dont think the application will see it unless you trap the exception... the message will be in some obscure log file.

The reason they cant crash the app is because if the servlet is taking a long time and the user gets bored and closes the browser, the same think happens... but its just a log message.

Take each other to lunch
I agree. Here's the link:
subject: Catch Error After Response Sent?
jQuery in Action, 3rd edition