Results 1 to 1 of 1
  1. #1
    userj2ee is offline Member
    Join Date
    May 2010
    Rep Power

    Question 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.

    Context initialContext;
    initialContext = new InitialContext();
    DataSource ds = (DataSource) initialContext.lookup(myjndiname);
    BasicDataSource bds = (BasicDataSource) datasource;"************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.

Similar Threads

  1. find a prime number
    By loja11 in forum Threads and Synchronization
    Replies: 4
    Last Post: 02-17-2011, 09:54 AM
  2. How to find the active Window in Swing?
    By akcasoy in forum AWT / Swing
    Replies: 16
    Last Post: 06-26-2010, 06:33 PM
  3. Find a number from a string
    By florentp in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 10:01 PM
  4. Find all permutations of a number
    By matzahboy in forum New To Java
    Replies: 6
    Last Post: 12-02-2008, 04:59 AM
  5. Find nth root of a number
    By perito in forum New To Java
    Replies: 1
    Last Post: 03-03-2008, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts