You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2013/08/12 23:55:46 UTC
svn commit: r1513274 -
/db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/LogicalConnection.java
Author: kmarsden
Date: Mon Aug 12 21:55:45 2013
New Revision: 1513274
URL: http://svn.apache.org/r1513274
Log:
DERBY-5560 Java deadlock between LogicalConnection40 and ClientXAConnection40
Patch contributed by Brett Bergquist
Modified:
db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/LogicalConnection.java
Modified: db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/LogicalConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/LogicalConnection.java?rev=1513274&r1=1513273&r2=1513274&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/LogicalConnection.java (original)
+++ db/derby/code/branches/10.10/java/client/org/apache/derby/client/am/LogicalConnection.java Mon Aug 12 21:55:45 2013
@@ -77,9 +77,14 @@ public class LogicalConnection implement
// ------------------------ logical connection close -------------------------
// All methods are simply forwarded to the physical connection, except for close() and isClosed().
- synchronized public void close() throws SQLException {
- try
- {
+ public void close() throws SQLException {
+ // The pooledConnection owns this LogicalConnection. To ensure that
+ // there is no deadlock when calling back into the pooledConnection_.recycleConnection
+ // below, we first synchronize on the pooledConnection and then on this
+ // LogicalConnection
+ synchronized (pooledConnection_) {
+ synchronized (this) {
+ try {
// we also need to loop thru all the logicalStatements and close them
if (physicalConnection_ == null) {
return;
@@ -90,7 +95,7 @@ public class LogicalConnection implement
if (physicalConnection_.isClosed()) // connection is closed or has become stale
{
- pooledConnection_.informListeners(new SqlException(null,
+ pooledConnection_.informListeners(new SqlException(null,
new ClientMessageId(
SQLState.PHYSICAL_CONNECTION_ALREADY_CLOSED)));
} else {
@@ -103,12 +108,12 @@ public class LogicalConnection implement
}
physicalConnection_ = null;
pooledConnection_.nullLogicalConnection();
- }
- catch ( SqlException se )
- {
+ } catch (SqlException se) {
throw se.getSQLException();
}
}
+ }
+ }
synchronized public void closeWithoutRecyclingToPool() throws SqlException {
if (physicalConnection_ == null) {