-----Original Message-----
From: Craig R. McClanahan <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Friday, September 03, 1999 2:03 PM
Subject: Re: Global ConnectionPool Servlet
>Dmitri Namiot wrote:
>
>> Hi,
>>
>> and what is the reason to keep connection pool in servlet ?
>> Why you can not have just java class, implements singleton
>> pattern ?
>>
>
>You can solve many cases of a need for a global connection pool object
using the Singleton
>pattern, with a static method to get the connection you need. However,
there's a few
>object-oriented design reasons why that might not be a good idea. Here's a
couple of them:
>
>* Static methods can be called from anywhere in your code,
> not just where you want it called. This makes tracking down
> bugs a lot harder, because you could be faced with accidental
> (or malicious, in some environments) scribbling on your globally
> accessible data.
>
>* As the name implies, a singleton means there is only one such
> object. What happens when you need to run an application that
> connects to two different databases, or run two different apps
> (each with their own pool) in the same environment?
You can take the same approach as the setAttribute. Identify a connection
pool based on a key and access via the singleton. Not really difficult to
do. Actually one of the connection pool that is available uses this approach
(check http://webdevelopersjournal.com/columns/connection_pool.html).
>
>Storing the connection pool for an application in the attributes of a
servlet context deals
>with these issues. The connection pool is available to all the servlets
(and JSP pages) in
>your application -- and only to those classes. You can have more than one
connection pool in
>the same app under different keys (if you need it), and you can install
multiple apps, each
>in their own servlet context, with no risk of access by one app's classes
to the other app's
>connection pool.
>
I'm not 100% sure that accessing via the getAttribute is better than
accessing via a singleton since you would need to cast the result from the
getAttribute all the time. Whereas accessing via a singleton is known.
However, it is definitely more flexible.
dino
___________________________________________________________________________
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