I don't know about mysql, but many database engines will not accept
anywhere close to 180 simultaneous Connections (I think 50 is the
default limit in Oracle).  The JDBC driver will start doing bad things
at apparently random times and probably crash the servlet container or
web app. This is partly what Connection pools are for and might not be a
good application for SingleThreadModel.

Paul Copeland, JOT Object Technologies, http://www.jotobjects.com

-------- Original Message --------
Date:    Mon, 27 May 2002 17:24:58 -0400
From:    Walt Black <[EMAIL PROTECTED]>
Subject: Re: set connection as instance variable ( servlet and mysql)

I don't see how this affects performance and I don't believe that it is
drastic and I believe it is straight-forward.  Oreilly's Java Servlet
Programming by Jason Hunter and William Crawford suggest such a method
for
creating a threadpool/connection pool.  In my opinion it is one of the
simplest means you could use to accomplish the task.  The only change
needed
to the source code is to implement SingleThreadModel which is
essentially a
marker interface with no methods,
make the local Connection variable an instance variable and and create
the
connection in the init() method.  Place any cleanup code in the destroy
method.  There's no need to develop a ConnectionPool class yourself or
integrate someone else's into your project.  It's simple and clean and
would
easily support an application for this user base (180 students).  This
does
not appear to be an enterprise application and so the simplest most
easily
supportable model should be used.  The fact that the originator of this
thread asked the questions suggests to me that the simplest route would
be
best.  Let the Servlet container manage the connection/thread pool.

On Monday 27 May 2002 04:06 pm, you wrote:
> Yes, but you may really effect performance, wouldn't you? Seems like a very
> drastic solution to me.. - especially since there's such an
> straight-forward alternative..:)
>
> Geeta
>
> Walt Black wrote:
> > 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 bet 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

___________________________________________________________________________
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