[jboss-cvs] JBossAS SVN: r110058 - branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 21 04:24:15 EST 2010
Author: jesper.pedersen
Date: 2010-12-21 04:24:14 -0500 (Tue, 21 Dec 2010)
New Revision: 110058
Modified:
branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
Log:
[JBPAPP-5596] Potential dead-lock
Modified: branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
===================================================================
--- branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java 2010-12-21 08:40:25 UTC (rev 110057)
+++ branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java 2010-12-21 09:24:14 UTC (rev 110058)
@@ -75,7 +75,7 @@
private final boolean readOnly;
- private ReentrantLock lock = new ReentrantLock();
+ private ReentrantLock lock = new ReentrantLock(true);
private final Collection cels = new ArrayList();
@@ -245,7 +245,7 @@
// because it looks too nasty to expect the connection handle
// to unlock properly in certain race conditions
// where the dissociation of the managed connection is "random".
- lock = new ReentrantLock();
+ lock = new ReentrantLock(true);
}
protected void lock()
@@ -275,7 +275,8 @@
protected void unlock()
{
- lock.unlock();
+ if (lock.isHeldByCurrentThread())
+ lock.unlock();
}
public Object getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
Modified: branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
===================================================================
--- branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java 2010-12-21 08:40:25 UTC (rev 110057)
+++ branches/JBPAPP_5_1/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java 2010-12-21 09:24:14 UTC (rev 110058)
@@ -49,7 +49,9 @@
{
private static final Logger log = Logger.getLogger(WrappedConnection.class);
- private BaseWrapperManagedConnection mc;
+ private volatile BaseWrapperManagedConnection mc;
+ private BaseWrapperManagedConnection lockedMC;
+ private int lockCount;
private WrapperDataSource dataSource;
@@ -79,6 +81,10 @@
if (mc != null)
{
mc.tryLock();
+ if (lockedMC == null)
+ lockedMC = mc ;
+
+ lockCount++;
}
else
throw new SQLException("Connection is not associated with a managed connection." + this);
@@ -86,12 +92,12 @@
protected void unlock()
{
- BaseWrapperManagedConnection mc = this.mc;
+ BaseWrapperManagedConnection mc = lockedMC;
+ if (--lockCount == 0)
+ lockedMC = null;
+
if (mc != null)
mc.unlock();
-
- // We recreate the lock when returned to the pool
- // so missing the unlock after disassociation is not important
}
public WrapperDataSource getDataSource()
More information about the jboss-cvs-commits
mailing list