[jboss-cvs] JBossAS SVN: r111638 - in branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector: src/main/org/jboss/resource/adapter/jdbc and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 17 15:43:45 EDT 2011


Author: jbertram at redhat.com
Date: 2011-06-17 15:43:44 -0400 (Fri, 17 Jun 2011)
New Revision: 111638

Modified:
   branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/build.xml
   branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
   branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
   branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/connectionmanager/JBossManagedConnectionPool.java
Log:
JBPAPP-6742

Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/build.xml
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/build.xml	2011-06-17 15:03:40 UTC (rev 111637)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/build.xml	2011-06-17 19:43:44 UTC (rev 111638)
@@ -354,9 +354,10 @@
         <include name="org/jboss/resource/adapter/jdbc/CachedPreparedStatement.class"/>
         <include name="org/jboss/resource/adapter/jdbc/PreparedStatementCache*.class"/>
         <include name="org/jboss/resource/adapter/jdbc/StatementAccess.class"/>
+        <include name="org/jboss/resource/adapter/jdbc/ReentrantLock.class"/>
         <include name="org/jboss/resource/adapter/jdbc/jdk5/*.class"/>
         <include name="org/jboss/resource/adapter/jdbc/jdk6/*.class"/>
-		<include name="org/jboss/resource/adapter/jdbc/URLSelectorStrategy.class"/>
+        <include name="org/jboss/resource/adapter/jdbc/URLSelectorStrategy.class"/>
         <include name="org/jboss/resource/adapter/jdbc/remote/*"/>
         <!-- JBAS-2250 hack -->
         <include name="org/jboss/ejb/plugins/cmp/jdbc/*" />

Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java	2011-06-17 15:03:40 UTC (rev 111637)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java	2011-06-17 19:43:44 UTC (rev 111638)
@@ -36,7 +36,6 @@
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.locks.ReentrantLock;
 
 import javax.resource.ResourceException;
 import javax.resource.spi.ConnectionEvent;
@@ -214,6 +213,32 @@
 
    public void cleanup() throws ResourceException
    {
+      boolean isActive = false;
+
+      if (lock.hasQueuedThreads())
+      {
+         Collection<Thread> threads = lock.getQueuedThreads();
+         for (Thread thread : threads)
+         {
+            Throwable t = new Throwable("Thread waiting for lock during cleanup");
+            t.setStackTrace(thread.getStackTrace());
+
+            mcf.log.warn(t.getMessage(), t);
+         }
+
+         isActive = true;
+      }
+
+      if (lock.isLocked())
+      {
+         Throwable t = new Throwable("Lock owned during cleanup");
+         t.setStackTrace(lock.getOwner().getStackTrace());
+
+         mcf.log.warn(t.getMessage(), t);
+         
+         isActive = true;
+      }
+
       synchronized (handles)
       {
          for (Iterator i = handles.iterator(); i.hasNext();)
@@ -221,8 +246,10 @@
             WrappedConnection lc = (WrappedConnection) i.next();
             lc.setManagedConnection(null);
          }
+
          handles.clear();
       }
+
       //reset all the properties we know about to defaults.
       synchronized (stateLock)
       {
@@ -241,11 +268,14 @@
             }
          }
       }
-      // I'm recreating the lock object when we return to the pool
-      // 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(true);
+
+      if (isActive)
+      {
+         // There are active lock - make sure that the JCA container kills
+         // this handle by throwing an exception
+
+         throw new ResourceException("Still active locks for " + this);
+      }
    }
 
    protected void lock()
@@ -275,8 +305,19 @@
    
    protected void unlock()
    {
-      if (lock.isHeldByCurrentThread())
+      if (lock.isLocked())
+      {
          lock.unlock();
+      }
+      else
+      {
+         mcf.log.warn("Owner is null");            
+         
+         Throwable t = new Throwable("Thread trying to unlock");
+         t.setStackTrace(Thread.currentThread().getStackTrace());
+
+         mcf.log.warn(t.getMessage(), t);
+      }
    }
 
    public Object getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
@@ -369,16 +410,19 @@
    {
       if(t instanceof SQLException)
       {
-         if(mcf.isStaleConnection((SQLException)t))
+         boolean stale = mcf.isStaleConnection((SQLException)t);
+
+         if(stale)
          {
             t = new StaleConnectionException((SQLException)t);           
          
          }else
          {
-            if(mcf.isExceptionFatal((SQLException)t))
+            boolean fatalException = mcf.isExceptionFatal((SQLException)t);
+
+            if(fatalException)
             {
                broadcastConnectionError(t);
-               
             }
          }
       }
@@ -404,6 +448,11 @@
          }
       }
 
+      // We need to unlock() before sending the connection error to the
+      // event listeners. Otherwise the lock won't be in sync once
+      // cleanup() is called
+      unlock();
+
       Exception ex = null;
       if (e instanceof Exception)
          ex = (Exception) e;

Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java	2011-06-17 15:03:40 UTC (rev 111637)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java	2011-06-17 19:43:44 UTC (rev 111638)
@@ -73,6 +73,8 @@
       this.mc = mc;
       if (mc != null)
          trackStatements = mc.getTrackStatements();
+      else
+         lockedMC = null;
    }
 
    protected void lock() throws SQLException

Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/connectionmanager/JBossManagedConnectionPool.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/connectionmanager/JBossManagedConnectionPool.java	2011-06-17 15:03:40 UTC (rev 111637)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/connectionmanager/JBossManagedConnectionPool.java	2011-06-17 19:43:44 UTC (rev 111638)
@@ -367,7 +367,6 @@
       return result;
    }
 
-
    /**
     * Test if a connection can be obtained using default values
     * @return True if a connection was obtained; otherwise false



More information about the jboss-cvs-commits mailing list