Connection can be an instance variable.
Have your servlet implement SingleThreadModel.
Create your database connection in the init() method of the servlet.
Voila! Instant thread/connection pool.  The draw back is that you do not
control the number of threads that will be created.  I'll be Tomcat will
create enough to support your needs.
Close connection and clean up in destroy() method.

My question is have you already proven that your current implementation
couldn't support 180 students?  Are you solving a real problem or a perceived
problem?


On Monday 27 May 2002 12:36 pm, you 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

Reply via email to