user121196
user121196

Reputation: 31020

does process still continue after client disconnects

when a client disconnects from a server request prematurely, does the server still carries out rest of the work?
specifically, in a Java Servlet doGet if I have the following code:


public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException 
{
   A();  //client disconnects after A(); 
   B(); 
   C();  
}

if client disconnects after A() is finished, would B and C still get executed?

Upvotes: 2

Views: 2161

Answers (2)

mindas
mindas

Reputation: 26713

It depends.

If during A() (or any other method) you would attempt to send the response (using res) back to the client, IOException would be thrown. If not caught, it would terminate the servlet execution.

Otherwise the calculation would carry on and exit after C().

Upvotes: 2

ShyJ
ShyJ

Reputation: 4640

Yes it would. The server does not know about the disconnection up until it tries to write sth to the output stream (as a response). Event then due to a proxy server in between or because of output stream buffering it may be hard to know that a client disconnected.

Upvotes: 5

Related Questions