开发者

Connection pooling showing INACTIVE connections in database

开发者 https://www.devze.com 2023-04-03 05:32 出处:网络
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 DriverAdapter

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());
    }fina开发者_运维问答lly{
        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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号