Hi,

I have an application deployed on jboss. DB used is db2. For monitoring purpose i need to get the number of active and idle connections at any point of time. I am trying to use commons-dbcp jar to get this data using BasicDataSourceClass. Following is the piece of code.

Context initialContext;
try {
initialContext = new InitialContext();
DataSource ds = (DataSource) initialContext.lookup(myjndiname);
logger.info("************CONNECTION POOL DATA->" + ds.getClass().getName() + "************" + ds.getClass() + "**************");
BasicDataSource bds = (BasicDataSource) datasource;
logger.info("************CONNECTION POOL DATA-> ACTIVE CONN=" + bds.getNumActive() + " IDLE CONN=" + bds.getNumIdle() + " INIT SIZE=" + bds.getInitialSize());
}
catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

This code gave a class cast exception at the point datasource is cast to BasicDataSource. The class name returned by ds is WrapperDataSource. I have few queries on this:-

1. What configurations do i need so that datasource returned by InitialContext is BasicDataSource? FYI i tried to add the BasicDataSourceFactory in db2-ds.xml. But it still didnt work


2. Is there any other way to find the number of active connections in a connection pool? I dont want any server specific solution.


Pls help.

Thanks