| Author |
Commons-dbcp - getting the active database connections
|
Prachi Desai
Greenhorn
Joined: Jan 12, 2011
Posts: 2
|
|
Hello All,
I have configured XA Datasource in JBOSS AS and the database is DB2. I want to get the number of active connections at any point of time for monitoring purpose. For that i tried using commons-dbcp. commons-dbcp has a BasicDataSource class which provides the API to get the actibve and idle connections.
Following is the code :
Context initialContext;
initialContext = new InitialContext();
DataSource ds = (DataSource) initialContext.lookup(myjndiname);
BasicDataSource bds = (BasicDataSource) datasource;
logger.info("************CONNECTION POOL DATA-> ACTIVE CONN=" + bds.getNumActive() + " IDLE CONN=" + bds.getNumIdle() + " INIT SIZE=" + bds.getInitialSize());
So when i try to cast my datasource object to basicDataSource, it gives ClassCast exception. I checked the class name of the datasource returned by initialcontext. It is returning WrapperDataSource and not Datasource and i guess that is the reason for classcastexception.
Can anyone pease tell me how to get the number of active connections using dbcp jar. I also cannot change the underlying db implementation as its a huge applicationa d a very old application.
Thanks
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26201
|
|
|
What datasource is it wrapping? Does it contain the basic data source?
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Commons-dbcp - getting the active database connections
|
|
|