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/14 18:00:15 UTC
svn commit: r1513941 - in /db/derby/code/branches/10.9: ./
java/client/org/apache/derby/client/am/LogicalConnection.java
Author: kmarsden
Date: Wed Aug 14 16:00:14 2013
New Revision: 1513941
URL: http://svn.apache.org/r1513941
Log:
DERBY-5560 Java deadlock between LogicalConnection40 and ClientXAConnection40
Patch contributed by Brett Bergquist
Modified:
db/derby/code/branches/10.9/ (props changed)
db/derby/code/branches/10.9/java/client/org/apache/derby/client/am/LogicalConnection.java
Propchange: db/derby/code/branches/10.9/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1513218
Modified: db/derby/code/branches/10.9/java/client/org/apache/derby/client/am/LogicalConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/client/org/apache/derby/client/am/LogicalConnection.java?rev=1513941&r1=1513940&r2=1513941&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/client/org/apache/derby/client/am/LogicalConnection.java (original)
+++ db/derby/code/branches/10.9/java/client/org/apache/derby/client/am/LogicalConnection.java Wed Aug 14 16:00:14 2013
@@ -76,9 +76,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;
@@ -89,7 +94,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 {
@@ -102,12 +107,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) {