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?

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.

Craig McClanahan

___________________________________________________________________________
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