Hi Bin: I'm not sure I see what you want to achieve, but briefly (unless you have very specialised needs) all you have to do is this: Declare a pool (say myPool) as a static variable in your servlet (say, MyServlet.java). Write code to initialise it in the init() method of this servlet. When the servlet is initiliazed, that code will be executed and your pool will be therafter available to your other classes/servlets via: MyServlet.myPool. (btw, the init() method is executed *exactly* once upon servlet initialization.. also only a single copy of the servlet exists in memory at any given time..)
Regards, Geeta bin cai wrote: > Thanks Geeta. > How about i using "serializable" or "synchronozied" > when i initialize servlet every time? > Thanks again and have a good day > bin > --- Geeta Ramani <[EMAIL PROTECTED]> wrote: > > Hi Bin: > > > > Defining connections as instance variables in your > > servlet will not work > > because as you rightly guessed you will have > > threading problems. Your solution > > is to create a pool. search among the archives (or > > google) for "Connection > > pool". > > > > Regards, > > Geeta > > > > bin cai wrote: > > > > > Hi, > > > My application is about online exam with java > > servlet > > > as tool, tomcat 3.2.3 as server solution , mysql > > 3.49 > > > as the backend. > > > considering 180 students take the exam at same > > time > > > within 50 minutes, there are a lot of transactions > > > with database. > > > what i did right now is to define connection in > > local > > > variable(within doGet or doPost method), every > > time > > > this servlet is called, new connection is created. > > > after transaction is done, this connection is > > closed. > > > I am worrying the speed.(it will comsume a lot > > > connection and time for open new connection). > > > > > > so I am thinking to define connection as instance > > > variable in every servlet, so it can save sometime > > to > > > open new connection. However, I am not sure if it > > will > > > cause multi-thread problem? How and when i can > > close > > > the connection. > > > > > > Thank you very much > > > bin > > > > > > > > > ______________________________________________________________________ > > > Find, Connect, Date! http://personals.yahoo.ca > > > > > > > > > ___________________________________________________________________________ > > > 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 > > > > ______________________________________________________________________ > Find, Connect, Date! http://personals.yahoo.ca > > ___________________________________________________________________________ > 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
