// 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)
{
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);
if (trace)
log.tracef("Another thread already got a connection tracked by transaction=%s tx=%s",
other, trackByTransaction);
cl = other;
}
// This is the connection for this transaction
cl.setTrackByTx(true);
tsr.putResource(mcp, cl);
if (trace)
log.tracef("Using connection from pool tracked by transaction=%s tx=%s", cl, trackByTransaction);
return cl;