Two Laptop Bag*
The moose likes Servlets and the fly likes Life time of a servlet - very important Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Life time of a servlet - very important" Watch "Life time of a servlet - very important" New topic
Author

Life time of a servlet - very important

Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
Hi all,
i have got a very basic question. i have a servlet which a number of users access. my question is, if a user closes the browser window in the middle of the servlet execution(i mean before the entire servlet is executed) will the servlet be killed instantly or will the servlet get fully executed before it is killed.
i hope my question is clear.
any help would be greatly appreciated.
Subbu


Subbu
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12756
    
    5
In a normal servlet container, there is only one instance of the servlet object. This object may be used by any number of Threads - one Thread per request. Managing the lifetime of a servlet instance is up to the servlet container.
If a browser closes a connection while the servlet is writing to it, an exception is thrown. If your servlet does not provide for catching the exception, the servlet engine catches it. Other Threads executing other requests are not affected unless your code uses instance variables incorrectly.
Nothing a request can do can kill a servlet unless you made a REALLY big coding mistake, typically when calling non-java functions.
Bill

------------------
author of:
Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
If a browser closes a connection while the servlet is writing to it, an exception is thrown...to be more specific
Thu Aug 20 09:53:19 GMT 1998: Servlet failed with Exception
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.write(SocketOutputStream.java, Compiled Code)
at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java, Compiled Code)
......so on and so forth..
mpr
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Life time of a servlet - very important
 
Similar Threads
Long literals
on getting loaded......
compile?????
Static Initialization Block