Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Commons-dbcp - getting the active database connections

 
Prachi Desai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What datasource is it wrapping? Does it contain the basic data source?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic