Dyapa Srikanth
Dyapa Srikanth

Reputation: 1241

Connection pooling showing INACTIVE connections in database

I am using connection pooling with SharedPoolDataSource in struts application. Application user pass the Connection parameters dynamically through user interface. I am creating object of DriverAdapterCPDS and assigning it to SharedPoolDataSource obj props.

SharedPoolDataSource tds = new SharedPoolDataSource();
            tds.setConnectionPoolDataSource(cpds);
            tds.setMaxActive(5);
            tds.setMaxIdle(2);
            tds.setMaxWait(50);
            tds.setTestOnBorrow(true);
            tds.setValidationQuery(validationQuery);

I am storing it in the hashtable of DBUtil class with company name as key. Like this app user assigns lot of database details associated with each company.

dbUtil.DSht.put(comp, tds);

From the another program (Swing App) user send company name. So that I need to get the datasource object respective to company and execute queries on that database which are assigned to the user. And return result as object.

So I wrote a function like this

public static Connection getClientConnection(String comp){
    Connection con = null;
    try{
        if(!dbUtil.DSht.contains(comp)){
            loadClientDataSource(comp);
        }
        DataSource ds = (DataSource)dbUtil.DSht.get(comp);            
        Idle:"+bds.getNumIdle());
        con = ds.getConnection();
    }catch(Exception e){
        e.printStackTrace();
        throw new DBUtilException("Unable to get the client connection object. Cause: "+e.getMessage());
    }        
    return con;
}

to close the database connection

public static void closeConnection(Connection con){
    try{
        if(con != null)
            con.close();
    }catch(Exception e){
        e.printStackTrace();
    }        
}

I am calling this closeConnection function in finally block

try{
        con = DBUtil.getClientConnection(comp);
        pstmt = con.prepareStatement(sqlQuery);            
        pstmt.executeQuery();
    }catch(SQLException sqle) {
        sqle.printStackTrace();
        throw new QueryException("Unable to add query. Cause: "+sqle.getMessage());
    }finally{
        DBUtil.closeStatement(pstmt);
        DBUtil.closeConnection(con);
    }

Is there any problem of using the connection pooling? After using this application database showing lot of INACTIVE connections associated to my computer. Even after closing the connection it is showing like that. I set only 2 MAXIDLE connections for the database.

What is the problem? Why it is showing that much of INACTIVE connections? Is there any problem if we put datasource in hashtable?

Upvotes: 0

Views: 4958

Answers (1)

Adisesha
Adisesha

Reputation: 5258

Do not worry about it, having session in INACTIVE state is not a anomaly. Check http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:914029001168

Upvotes: 1

Related Questions