Scott,

Yes, the pool can instianted by some servlet that is set to run on startup.

This servlet starts the pool in its init() method and can add it to the
servlet context
as an attribute.  In this way, all the servlets in the context will have
access to the pool.

Example
//To start
Pool pool = new Pool(20);
getServletContext().setAttribute("ThePool", pool);

//In a servlet's service method:
Pool pool = (Pool)getServletContext().getAttribute("ThePool");
Connection con = pool.getConnection();

//do stuff

pool.returnConnection(con);

As far as the refresh, yes.  You'd have to start another thread on a
timer to do
this.

Disclaimer: Starting threads in a servlet container is beyond the scope
of this post. :)

Seriously, it's not too bad.  Just be careful about all your exceptions
and read up on
the servlet lifecycle, be careful to synchronzie, and you'll be on your way.

Mike

Scott Watson wrote:

> I have been reading this list for a couple of weeks now and have been scanning the 
>archives but I cannot find the answer to the
> question I am currently stuck on.
>
> I would like to know how the creation of a connection pool works.  I understand how 
>the Pooling mechanism works and why it should be
> used (I am an Oracle DBA) but what I don't understand is how it is instantiated in 
>the servlet container and remains in the
> container available for all servlets in the application.
>
> Where does the connection manger get started and how do you ensure that it is 
>available for all servlets to use within the context
> of an application.  When I was playing around with Tomcat and a simple servlet that 
>created its own connection I noticed the destroy
> method was called not too long after there had been no activity.  Therefore how does 
>the connection pool get created? I.e. each
> servlet asks for a connection from the pool if it exits otherwise creates the pool 
>and the connection is returned?
>
> Is there some "on load/on startup" servlet that can possibly create the connection 
>pool before any other servlet loads.  For example
> say I had a code table in a database that I would like to keep in a servlet context 
>and refresh every 15 minutes (can this sort of
> operation be done).
>
> Thanks for your help in advance,
> Scott.
>
> ___________________________________________________________________________
> 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
>

___________________________________________________________________________
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