pradeep asks:
> I am modifying a site to which the number hits per month is very
> high.earlier it was implemented with CGI scripts and now I am changing it to
> 3-tier web application with Servlets on web server.
>
> When evaluated the pros and cons I am strucked up with the question of
> solving the scalability problem.I can not keep on generating connections to
> the database in response to the client request to query the database
Aside from any servlet engine facilities for pooling database
connections, why not just instantiate a database connection as an
instance variable in the servlet, and keep it open?
Or, if each request takes a while to complete, code a database
connection pool object - it would keep a vector of connection objects,
and let each servlet invocation check a connection out when it starts
and check it back in when it's done.
Either use some sort of simple delegation/composition where your
own poolableDatabaseConnection class contains a connection object, a
boolean variable for whether it's available or not, and maybe some
sort of timestamp and thread ID if you need to add cleanup code to
make sure all connections get checked back in eventually. Then you
just have your pool object go through an array of
poolableDatabaseConnection objects, looking for the first available
connection, setting its available boolean to false and returning a
reference.
Or use a double set of vectors, one to hold the avaialable
connections and one to hold the checked out connections; when a
connection gets checked out, move it to the notAvailable vector, when
the servlet checks it back in, move it to the available vector.
Then have each servlet invocation check a connection out if it
needs one. If none are available, they have to loop and wait until
some are. If that gets intolerable, then either you need bigger &
better servers, or you're coding something wrong and your servlets are
hanging on to the database connections too long (either because you're
forgetting to let go of them or your code is taking too long to do
whatever you need to do :-).
I'm not sure how you'd have this work if you need to support
multiple servlets. I haven't worked much with servlets communicating
with each other. Presumably you could make the connection pool
available to all of the servlets. I'm still hazy on the nuances of
static classes or a singleton, though I suppose they would make sense
if all of the servlets are running under the same JVM with your
servlet engine.
Steven J. Owens
[EMAIL PROTECTED]
[EMAIL PROTECTED]
___________________________________________________________________________
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