Adam Gifford wrote:

> What happens when a user hits 'esc' or stops their connection in
> progress to jserv?  i am wondering because we have a servlet that takes
> some time to run & query a db and it doesn't seem that the db connection
> is getting shut down when they cancel running servlet.  Is there
> someplace i can out a call to shutdown teh connection to the db?
>

What happens is that the servlet is generally oblivious to the fact that
the user cancelled the request.  It will keep on doing its processing, and
attempt to return the response.

You may or may not encounter an IOException when writing the results back
out (depends on bufffering and which particular servlet engine you are
using).  But if you do encounter such an exception and don't trap it
yourself, then any code in your servlet after that will not get executed,
because the service() and doGet()/doPut() methods of the servlet will throw
the IOException back to the servlet engine.

It also sounds from your question like you are opening and closing the
database connection on every request.  If this is so, you will get much
better overall performance if you use a connection pool of some sort that
is initialized in the init() method, and shut down in the destroy()
method.  Then, for each request, all you need to do is:
* Allocate yourself a connection from the pool
* Do the processing that is required
* Return the connection to the pool

You have to be aware of multithreading issues, and in particular make sure
you *always* return the connection to the pool at the end of your request
processing -- otherwise you will eventually use up all the connections in
your pool and servlet processing will hang or throw an exception (depending
on how the particular connection pool you are using deals with it).

There are a variety of connection pools around the web, and examples of
this approach in the various servlet books.

Craig McClanahan




----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
READ THE FAQ!!!!     <http://java.apache.org/faq/>
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to