tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john-paul delaney ...@justatest.com>
Subject RE: OT: db pool problems - jdbc connection count?
Date Fri, 31 Oct 2003 00:03:35 GMT
Oscar... I'll keep a close lookout for when you publish your HOWTO.  In the meantime, I'll
try to follow Yoav's instructions, and get back to the list with any eventual errors I make.

thanks again to you both,
/j-p.


On Thu, 30 Oct 2003, Oscar Carrillo wrote:

> Thanks for a more complete solution Yoav!
> 
> I'm still using a homebrew connection pool, so I'm lacking in some
> features. I'm planning on moving to one of the standard connection pools
> since they exist now and look quite good.
> 
> Can I put your example up on my site when I finally get to doing a HOWTO
> on how to do connection pools?
> 
> Regards,
> Oscar
> 
> On Thu, 30 Oct 2003, Shapira, Yoav wrote:
> 
> > 
> > Howdy,
> > It's very similar to how you get a connection.  Let's say your
> > datasource is defined in server.xml with name "jdbc/myDataSource".
> > Then:
> > 
> > InitialContext ic = new InitialContext();
> > DataSource ds = (DataSource)
> > ic.lookup("java:comp/env/jdbc/myDataSource");
> > 
> > If you wanted a connection, you'd call ds.getConnection().  But you want
> > to find the number of active connections, which is not part of the
> > DataSource interface.  So you need to cast ds to the specific type,
> > which is the type your specified in server.xml.
> > 
> > Assuming that type is org.apache.commons.dbcp.BasicDataSource, you'd do:
> > BasicDataSourcs bds = (BasicDataSource) ds;
> > int numActive = bds.getNumActive();
> > int numIdle = bds.getNumIdle();
> > System.out.println("There are " + numActive + 
> > " active connections and " + numIdle + 
> > " idle connections in the pool.");
> > 
> > I'm assuming you're using DBCP.  If you're using another connection
> > pool, the above code must be modified accordingly.
> > 
> > Yoav Shapira
> > Millennium ChemInformatics
 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message