Results 1 to 1 of 1
- 01-13-2011, 05:57 AM #1Member
- Join Date
- May 2010
- Rep Power
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.
Last edited by userj2ee; 01-13-2011 at 06:07 AM.
- By loja11 in forum Threads and SynchronizationReplies: 4Last Post: 02-17-2011, 09:54 AM
- By akcasoy in forum AWT / SwingReplies: 16Last Post: 06-26-2010, 05:33 PM
- By florentp in forum New To JavaReplies: 2Last Post: 03-20-2009, 10:01 PM
- By matzahboy in forum New To JavaReplies: 6Last Post: 12-02-2008, 04:59 AM
- By perito in forum New To JavaReplies: 1Last Post: 03-03-2008, 07:51 AM