// 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.
ConnectionListener cl = mcp.getConnection(subject, cri);
if (trace)
log.tracef("Got connection from pool tracked by transaction=%s tx=%s", cl, trackByTransaction);
TransactionSynchronizationRegistry tsr = getTransactionSynchronizationRegistry();
Lock lock = getLock();
try
{
lock.lockInterruptibly();
}
catch (InterruptedException ie)
{
Thread.interrupted();
throw new ResourceException(bundle.unableObtainLock(), ie);
}
try
{
// Check we weren't racing with another transaction
ConnectionListener other =
(ConnectionListener)tsr.getResource(mcp);
if (other != null)
{
mcp.returnConnection(cl, false);