tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Updated Docs for Tomcat 4
Date Mon, 10 Sep 2001 12:02:55 GMT

Connection-pooling based on the Tyrex stuff is straightforward.  If you do
the Tyrex install and resource setup as
indicated in the new doc, you already have everything needed to do basic
connection pooling. Below is the code
from the new doc, modified:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/EmployeeDB");

Connection conn;

if ( dataSrc instanceof ConnectionPoolDataSource )
     ConnectionPoolDataSource poolDataSrc
= (ConnectionPoolDataSource)dataSrc;
     PooledConnection         pc = poolDataSrc.getPooledConnection();

     conn = pc.getConnection();
     conn = ds.getConnection();

... use this connection to access the database ...

Again, in the default Tyrex config, the DataSource you get will have the
concrete class tyrex.jdbc.xa.XADataSourceImpl,
which implements ConnectionPoolDataSource.

I suggest you do all this in an init(), and use a static or singleton to
manage the data-source retrieved via JNDI --
don't do the JNDI lookup every time you need a connection.

When you use Tyrex like this, a background thread is created that will
close unused connections every 10 secs or so.
The pool therefore stays close to the minimum required size at all times,
but if your DB takes a long time to
establish connections, you'll experience delays when there is a spike in
activity.  If you want more control over how the
pool is managed, I suggest you look into, for example, Poolman

- Fernando

                    Rick Mann                                                            
                    <rmann@latency       To:     <>,
"Craig R. McClanahan" <>, "tomcat user    
          >   " <>
                                         cc:     (bcc: Fernando Salazar/CAM/Lotus)       
                    09/09/2001           Subject:     Re: Updated Docs for Tomcat 4      
                    09:50 PM                                                             
                    Please respond                                                       
                    to tomcat-dev                                                        

on 9/5/01 9:04 PM, Craig R. McClanahan at wrote:

> Things still on the TODO list:
> * Configuration instructions for populating the JNDI context that
> is provided to web applications (such as connection pools).

Erg...ack...grr! I looked at the latest docs up close! I really
want to know how to make connection pools!

Anyway, keep it up. It's coming together.


Roderick Mann               rmann @

View raw message