That's still not quite right.  Although it is straying a little from the
topic of servlets in general, it is in Jason's book, so it should
probably be cleared up...

The ConnectionPool is only one type of ObjectPool.  Your code didn't
indicate too clearly, but the servlet should not be calling a
constructor for the pool.  Rather, it should use a static method like:
ConnPool pool = ConnPool.getPool();

The  method you showed (of testing it for null and using lazy
instantiation) should be done by the ConnectionPool class via a private
constructor method.

You can then say:
Connection conn = pool.getConnection();

...and retrieve a Connection object from the pool.  Note that there are
differeing philosophies when using object pools.  The pool class can
create a pool of resources on instantiation, and/or add new instances to
the pool when it has none to allocate and simply not destroy them when
the resource is freed.  Again, I'd recommend Grand's book, as he goes
into some detail about ObjectPools in general, which is what your
question is really about...

> I have different users logging in, I
> am unable to get their user ID and password, as the variables have not
> yet been initialised.
Well, then you won't be able to use this particular pattern...
ObjectPools are for instances when one object is virtually identical to
another, such that it doesn't matter which instance a client uses.
While it would work for a hard coded (e.g. guest) account, it will not
serve well for a connection based on an individual's login and
password...

--
Within C++ is a smaller, cleaner language
struggling to get out.
It's called Java.

Thomas Moore
[EMAIL PROTECTED]        Home Account
Software.Engineer         [EMAIL PROTECTED]
phone://732.462.1880:268  NJ Patterns Group Home Page
employer://Celwave, RF    http://members.home.net/twmoore/cjpg

___________________________________________________________________________
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