I favour the , get it , use it , return it approach. That to me means connection pooling and constantly getting and releasing connections whenever they are needed and no longer needed.
If you hold a connection in init you will be susceptable to concurrency issues caused by multiple threads running for one instance of your servlet. I believe destroy is called when the server is shutdown. Jason's Hunter's book covers life cycle issues pretty well. > -----Original Message----- > From: A mailing list for discussion about Sun Microsystem's Java > Servlet API Technology. [mailto:[EMAIL PROTECTED]]On > Behalf Of Zeng, Feng_Hua (CAP,CEF) > Sent: Tuesday, May 01, 2001 6:32 PM > To: [EMAIL PROTECTED] > Subject: How to use connection pooling in servlet's init() and destroy() ? > > > Hello, fellows, > > As is the title, in a servlet > [1] may I obtain a DB connection from the pool in "init()" > and release it back to the pool in "destroy()" ? > For, I remember, when "connection pooling" > has not been so popular as today, there are samples > which create DB connections and even prepare statements > in "init()" and close them in "destroy()", in order to > improve its performance reportedly. > > Or, while taking advantage of connection pooling, > [2] must I obtain and release a connection only > in a servlet's "doPost()" or "doGet()" ? > Someone explained that > if a connection is obtained in "init()", it will keep > occupied so never released until "destroy()". > So here what confuses me is > [3] when on earth "destroy()" is called ? > [4] What is the exact meaning of > "the end of a servlet's life cycle" ? > If there exist several requests for the same servlet > at the same time, > [5] is "init()" called only once ? > If a member variable ( not static ) > is given a new value, > [6] will it be shared by > all the instances of the servlet > ( like the case in [1] ) ? > > Thank you for your help. > > ---------------------------------------- > [EMAIL PROTECTED] > Office: Tokyo, Japan http://www.gecapital.com > Home: Dalian, Liaoning, China (Hometown: Hunan) > ---------------------------------------- > > __________________________________________________________________ > _________ > To unsubscribe, send email to [EMAIL PROTECTED] and include > in the body > of the message "signoff SERVLET-INTEREST". > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > Resources: http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
