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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]]
> > > Sent: Tuesday, August 07, 2001 10:27 AM
> > > To: [EMAIL PROTECTED]
> > > 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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]]
> > > > > Sent: Tuesday, August 07, 2001 9:07 AM
> > > > > To: [EMAIL PROTECTED]
> > > > > 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
> > times
> > > > that
> > > > > tomcat is up.  My questions include:
> > > > > 
> > > > >  Is this correct that there is no way to
> > reconnect
> > > > to
> > > > > the database?  If this is not correct, how
> > does
> > > > one
> > > > > reconnect, and or reinitialize the servlet?
> > > > >  Is keeping the persistent connection to the
> > > > database
> > > > > a heavy burden on tomcat?  In other words, is
> > it
> > > > o.k.
> > > > > to design an application which never releases
> > its
> > > > > conenction to the database?
> > > > >  
> > > > > 
> > > > >   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.
> > > > > 
> > > > >
> > __________________________________________________
> > > > > Do You Yahoo!?
> > > > > Make international calls for as low as
> > $.04/minute
> > > > with 
> > > > > Yahoo! Messenger
> > > > > http://phonecard.yahoo.com/
> > > > > 
> > > 
> > > 
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Make international calls for as low as $.04/minute
> > with 
> > > Yahoo! Messenger
> > > http://phonecard.yahoo.com/
> > > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
-- 

Andrew Robson         
        
tel: (0141) 424 0607    
mobile: 07759 430234    
email: [EMAIL PROTECTED]

Reply via email to