*/
private ConnectionListener getTransactionNewConnection(TransactionLocal trackByTx, Transaction trackByTransaction,
ManagedConnectionPool mcp, Subject subject, ConnectionRequestInfo cri)
throws ResourceException
{
ConnectionListener cl = null;
// Need a new one for this transaction
// This must be done outside the tx local lock, otherwise
// the tx timeout won't work and get connection can do a lot of other work
// with many opportunities for deadlocks.
// Instead we do a double check after we got the transaction to see
// whether another thread beat us to the punch.
cl = mcp.getConnection(subject, cri);
if (trace)
{
dump("Got connection from pool tracked by transaction " + cl + " tx=" + trackByTransaction);
}
// Relock and check/set status
try
{
trackByTx.lock(trackByTransaction);
}
catch (Throwable t)
{
mcp.returnConnection(cl, false);
if (trace)
{
dump("Had to return connection tracked by transaction " + cl + " tx=" +
trackByTransaction + " error=" + t.getMessage());
}
JBossResourceException.rethrowAsResourceException("Unable to get connection from the pool for tx="
+ trackByTransaction, t);
}
try
{
// Check we weren't racing with another transaction
ConnectionListener other = (ConnectionListener) trackByTx.get(trackByTransaction);
if (other != null)
{
mcp.returnConnection(cl, false);
if (trace)
{