tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Tyrex Pools
Date Tue, 02 Oct 2001 14:11:23 GMT

Will, I also found getting Datasources in a servlet init method yields new
connections for each getConnection().  However, If I casted the Datasource
to a ConnectionPoolDataSource, pooling works.

Try getting a ConnectionPoolDataSource in the init method.  Something like:

public void init( ServletConfig config ){

            Context ic = new InitialContext();
            cpds = (ConnectionPoolDataSource)ic.lookup(dbName);

then use the cpds to get a PooledConnection, and finally a Connection from

doGet {
     PooledConnection pc = cpds.getPooledConnection();
     conn = pc.getConnection();

Still, I'm not sure why just using a Datasource doesn't use pooling.  I
believe it should & that the application layer should not be getting
ConnectionPoolDataSources & PooledConnections.


                    Will Stranathan                                                      
                    <will@thestrana       To:       
          >            cc:     (bcc: Craig Reichenbach/CAM/Lotus)  
                                          Subject:     Re: Tyrex Pools                   
                    11:42 PM                                                             
                    Please respond                                                       
                    to tomcat-dev                                                        

Ah - that makes sense.  However, it seems to still be doing the same
thing.  I just threw together a simple JSP to test it, and put the ds
lookup in jspInit().  The lookup is only getting executed once, but it
still looks like no connections are getting re-used.

Anything else for me to look at?

Will Stranathan

     DataSource ds = null;
     public void jspInit() {
         try {
             Context ctx = new InitialContext();
             ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Directory");
             System.out.println("did lookup");
         } catch (Exception e) {

     Connection conn = null;
     if (ds != null) {
         try {
             conn = ds.getConnection();


Remy Maucherat wrote:

> Instead, I would retrieve the DataSource in the init() method of the
> servlet, and put it in an instance variable.
> Remy

View raw message