commons-dbcp - Getting the active and idle db connections
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.
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());
This code gave a class cast exception at the point where datasource is cast to BasicDataSource. The class name returned by variable "ds" is WrapperDataSource and not DataSource which is why class cast exception was thronw. Does anyone know :-
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. I also cannot change the underlying functionality of db pool implementation as its a huge application.