tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "A.L." <amoslie...@yahoo.com>
Subject RE: Servlet/ Database Conenction Persists Question
Date Tue, 07 Aug 2001 20:22:56 GMT
Andrew,
   Thank you for your response.  I appreciate you
clarifying the topic, nevertheless it seems to me a
little troubling to assume that the servlet should
only be destroyed by the servlet.   (I'm new to
servlets, but by servlet engine, I am assuming you
mean tomcat).

   Here is why.  Lets say there is an application
whose web interface is run by servlets, while the
desktop app isn't.  If there is a problem with the
database which needs to be fixed I would ahave to stop
tomcat so that I may gain complete access to the
database.  In Microsoft Access for example I cannot
enter design view if a servlet has an existing
connection.  Which means I will have to stop the
complete web application even though the only part
which needs to be destroyed is the servlet with the db
connection.   i would like to destroy the servlet
temporarily, and then reinitialize it via the web.
Would this be possible?



--- Andrew Robson <andrewdrobson@netscapeonline.co.uk>
wrote:
> Amos,
>   Forgive if I've misunderstood but I get the
> impression you 
> are not clear about the servlet lifecycle. 
> The init method will be called once. (when exactly
> is dependant
> on your servlet engine but it will be before any
> client requests)
> You then have a single servlet instance which
> handles multiple requests
> - each of which will be handled by a seperate
> thread.
> (I'm simplifying a bit because some servlet engines
> will 
> create a servlet instance per request in
> implementing 
> the SingleThreadModel but leave that to one side
> just now)
> It is the responsibility of the servlet engine to
> call destroy()
> Typically when the servlet engine is shutdown.
> So basically your servlet is running for the same
> period
> of time as the servlet engine. For the lifetime of
> your servlet
> engine you would only expect init and destroy to be
> called once
> for each servlet.
> It is not like CGI where each request fires up a
> process 
> to run a new instance of your program.
> 
> Hope this helps and apologies if I'm telling you
> something
> you already know.
> 
> andrew
> 
> On Tue, 07 Aug 2001, you wrote:
> > William,
> >    thanks.  IOt turns out that after looking at my
> > problem in a little more detail, I figured this
> must
> > be the issue.  I guess this leads to another
> question.
> >  Once you destroy a servlet, can you reinitialize
> it. 
> > If so how?
> > 
> > thanks,
> >    -Amos
> > --- William Kaufman <WKaufman@viquity.com> wrote:
> > > > This is not really a jdbc issue.  What is
> > > happening is
> > > > that my code specifies that the conenction to
> the
> > > > database is made only during the init of the
> > > servlet
> > > > and the conenction is closed after the servlet
> is
> > > > destroyed.
> > > 
> > > Ah, OK.  Don't do that.
> > > 
> > > init() is called exactly once, when the servlet
> gets
> > > loaded.
> > > 
> > > If you want to close and re-allocate the
> connection,
> > > do it in your
> > > doGet()/doPost()/doWhatever() methods (if you've
> > > overridden those) or in
> > > your service() method (if you didn't): connect
> at
> > > the beginning,
> > > commit/rollback and close at the end
> (preferrably in
> > > a "finally" block, to
> > > make sure it gets done).
> > > 
> > >                                         -- Bill
> K. 
> > > 
> > > > -----Original Message-----
> > > > From: A.L. [mailto:amoslieber@yahoo.com]
> > > > Sent: Tuesday, August 07, 2001 10:27 AM
> > > > To: tomcat-user@jakarta.apache.org
> > > > Subject: RE: Servlet/ Database Conenction
> Persists
> > > Question
> > > > 
> > > > 
> > > > This is not really a jdbc issue.  What is
> > > happening is
> > > > that my code specifies that the conenction to
> the
> > > > database is made only during the init of the
> > > servlet
> > > > and the conenction is closed after the servlet
> is
> > > > destroyed.  I think that my problem is that
> once I
> > > > destroy the servlet, I can't figure a way to
> re
> > > > initialize it.  Simply refreshing the servlet
> page
> > > > doesn;t seem to work.
> > > > --- William Kaufman <WKaufman@viquity.com>
> wrote:
> > > > > >     I have developed a servlet web
> application
> > > > > which
> > > > > > connects to a database to retrieve
> > > information.  I
> > > > > > noticed that if within my servlet I
> destroy
> > > the
> > > > > > connection to the database there is no way
> to
> > > > > > reconnect to the database .
> > > > > 
> > > > > Maybe this is a JSP thing (I'm not too
> familiar
> > > with
> > > > > those), and JSPs have
> > > > > some weird JDBC cover methods.  But you
> _should_
> > > be
> > > > > able to disconnect, by
> > > > > calling Connection.close(); and to
> reconnect,
> > > the
> > > > > same way you connected the
> > > > > first time.
> > > > > 
> > > > > Why can't you reconnect?  Are you getting an
> > > > > exception from
> > > > > DriverManager.getConnection()?
> > > > > 
> > > > > >  Is keeping the persistent connection to
> the
> > > > > database
> > > > > > a heavy burden on tomcat?
> > > > > 
> > > > > Persistent connections aren't a burden on
> > > Tomcat,
> > > > > but might be on your
> > > > > database, especially if the modifications
> aren't
> > > > > committed immediately.  You
> > > > > should always try to close connections (and
> > > other
> > > > > resources) if you don't
> > > > > think you'll be using it again in a few
> seconds.
> > > > > 
> > > > > >   I don't believe my question pertains
> > > > > specifically to
> > > > > > Tomcat, so I was wondering whether or not
> any
> > > of
> > > > > you
> > > > > > knew where there are list servers which
> deal
> > > with
> > > > > > servlets in general.
> > > > > 
> > > > > This mailing list is fine for general
> servlet
> > > > > questions.  But this seems to
> > > > > be a JDBC question,...
> > > > > 
> > > > >                                         --
> Bill
> > > K. 
> > > > > 
> > > > > > -----Original Message-----
> > > > > > From: A.L. [mailto:amoslieber@yahoo.com]
> > > > > > Sent: Tuesday, August 07, 2001 9:07 AM
> > > > > > To: tomcat-user@jakarta.apache.org
> > > > > > Subject: Servlet/ Database Conenction
> Persists
> > > > > Question
> > > > > > 
> > > > > > 
> > > > > >     I have developed a servlet web
> application
> > > > > which
> > > > > > connects to a database to retrieve
> > > information.  I
> > > > > > noticed that if within my servlet I
> destroy
> > > the
> > > > > > connection to the database there is no way
> to
> > > > > > reconnect to the database .  In other
> words I
> > > need
> > > > > to
> > > > > > keep my connection to the database at all
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Mime
View raw message