Fix [Find|Spot]Bugs locking warning
@@ -174,7 +174,6 @@ public class ManagedConnection<C extends Connection> extends DelegatingConnectio
@Override
public void close() throws SQLException {
if (!isClosedInternal()) {
- try {
// Don't actually close the connection if in a transaction. The
// connection will be closed by the transactionComplete method.
//
@@ -183,15 +182,19 @@ public class ManagedConnection<C extends Connection> extends DelegatingConnectio
// be modified by the transactionComplete method which could run
// in the different thread with the transaction calling back.
lock.lock();
+ try {
if (transactionContext == null || transactionContext.isTransactionComplete()) {
super.close();
}
} finally {
+ try {
setClosedInternal(true);
+ } finally {
lock.unlock();
}
}
}
+ }
/**
* Delegates to {@link ManagedConnection#transactionComplete()} for transaction completion events.
@@ -209,8 +212,11 @@ public class ManagedConnection<C extends Connection> extends DelegatingConnectio
protected void transactionComplete() {
lock.lock();
+ try {
transactionContext.completeTransaction();
+ } finally {
lock.unlock();
+ }
// If we were using a shared connection, clear the reference now that
// the transaction has completed
