openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AndyG <andy.gumbre...@orprovision.com>
Subject Re: DBCP Connection pool blocks threads on open/close connections
Date Tue, 15 Feb 2011 09:50:03 GMT

Found this post that is pretty close to what you are experiencing.

https://issues.apache.org/jira/browse/DBCP-277?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Their suggestion is to use a more recent version of DBCP, but this is not
really going to be an option as OpenEJB packages 1.3.

Starvation occurs when all your 30 checked out connections cannot be put
back - due to the above bug in DBCP.

What I would suggest is that you ensure that your DbHelper.closeConnection
and I presume DbHelper.getConnection are internally synchronized on the same
static final Object - Or if you don't have access to that code then wrap it
in your own synchronized factory.

public static Connection getConnection() throws Throwable {
    final Connection con;
    synchronized(LOCK){
        con = ...get the con...
    }

    return con;
}

public static void closeConnection(final Connection con){    
    synchronized(LOCK){
        if(null != con){
            ...really make sure this con is closed, catch and log Throwable
etc.
        }
    }
}

Also:

grigory wrote:
> 
> We do request multiple connections within single transaction.
> 

Not to the same database I hope? A connection can create as many statements
as required for any unit of work. You should be passing about a single
connection to the same database within the transaction / thread scope - give
the connection back before you leave the scope and do not return from the
current thread scope until 'after' the finally.

Enter scope...
Get con...
Do work..(Do not return here)
finally{
    Close con...
}
Return from scope here...

You should drop the connection test unless you actually get stale connection
issues. 
TestOnBorrow false

-- 
View this message in context: http://openejb.979440.n4.nabble.com/DBCP-Connection-pool-blocks-threads-on-open-close-connections-tp3303674p3306483.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Mime
View raw message