Author: markt
Date: Tue Jun 19 09:29:10 2018
New Revision: 1833799
URL: http://svn.apache.org/viewvc?rev=1833799&view=rev
Log:
Fix [Find|Spot]Bugs locking warning
Modified:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java
Modified:
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java?rev=1833799&r1=1833798&r2=1833799&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/managed/ManagedConnection.java
Tue Jun 19 09:29:10 2018
@@ -174,21 +174,24 @@ public class ManagedConnection<C extends
@Override
public void close() throws SQLException {
if (!isClosedInternal()) {
+ // Don't actually close the connection if in a transaction. The
+ // connection will be closed by the transactionComplete method.
+ //
+ // DBCP-484 we need to make sure setClosedInternal(true) being
+ // invoked if transactionContext is not null as this value will
+ // be modified by the transactionComplete method which could run
+ // in the different thread with the transaction calling back.
+ lock.lock();
try {
- // Don't actually close the connection if in a transaction. The
- // connection will be closed by the transactionComplete method.
- //
- // DBCP-484 we need to make sure setClosedInternal(true) being
- // invoked if transactionContext is not null as this value will
- // be modified by the transactionComplete method which could
run
- // in the different thread with the transaction calling back.
- lock.lock();
if (transactionContext == null ||
transactionContext.isTransactionComplete()) {
super.close();
}
} finally {
- setClosedInternal(true);
- lock.unlock();
+ try {
+ setClosedInternal(true);
+ } finally {
+ lock.unlock();
+ }
}
}
}
@@ -209,8 +212,11 @@ public class ManagedConnection<C extends
protected void transactionComplete() {
lock.lock();
- transactionContext.completeTransaction();
- lock.unlock();
+ try {
+ transactionContext.completeTransaction();
+ } finally {
+ lock.unlock();
+ }
// If we were using a shared connection, clear the reference now that
// the transaction has completed
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]