felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1371288 - in /felix/trunk/scr: pom.xml src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
Date Thu, 09 Aug 2012 16:18:49 GMT
Author: djencks
Date: Thu Aug  9 16:18:49 2012
New Revision: 1371288

URL: http://svn.apache.org/viewvc?rev=1371288&view=rev
Log:
FELIX-3456 Track how lock was obtained, and try to do a thread dump on lock problems

Modified:
    felix/trunk/scr/pom.xml
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java

Modified: felix/trunk/scr/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/pom.xml?rev=1371288&r1=1371287&r2=1371288&view=diff
==============================================================================
--- felix/trunk/scr/pom.xml (original)
+++ felix/trunk/scr/pom.xml Thu Aug  9 16:18:49 2012
@@ -331,6 +331,9 @@
                         <ignore>java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock</ignore>
                         <ignore>java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock</ignore>
                         <ignore>java.util.concurrent.TimeUnit</ignore>
+                        <ignore>java.lang.management.ManagementFactory</ignore>
+                        <ignore>java.lang.management.ThreadInfo</ignore>
+                        <ignore>java.lang.management.ThreadMXBean</ignore>
                     </ignores>
                 </configuration>
                 <executions>

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=1371288&r1=1371287&r2=1371288&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
Thu Aug  9 16:18:49 2012
@@ -18,6 +18,9 @@
  */
 package org.apache.felix.scr.impl.manager;
 
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
 import java.security.Permission;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -31,7 +34,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import EDU.oswego.cs.dl.util.concurrent.ReaderPreferenceReadWriteLock;
 import org.apache.felix.scr.Component;
 import org.apache.felix.scr.Reference;
 import org.apache.felix.scr.impl.BundleComponentActivator;
@@ -97,6 +99,9 @@ public abstract class AbstractComponentM
 
     private long m_timeout = 5000;
 
+    private Thread lockingThread;
+    private Throwable lockingStackTrace;
+
     /**
      * The constructor receives both the activator and the metadata
      *
@@ -162,7 +167,15 @@ public abstract class AbstractComponentM
         {
             if (!m_stateLock.tryReadLock( m_timeout ) )
             {
-                throw new IllegalStateException( "Could not obtain lock in " + m_timeout
+ " milliseconds for component " + m_componentMetadata.getName() );
+                try
+                {
+                    dumpThreads();
+                }
+                catch ( Throwable e )
+                {
+                     //we are on a pre 1.6 vm, no worries
+                }
+                throw ( IllegalStateException ) new IllegalStateException( "Could not obtain
lock in " + m_timeout + " milliseconds for component " + m_componentMetadata.getName() ).initCause(
lockingStackTrace );
             }
         }
         catch ( InterruptedException e )
@@ -188,6 +201,8 @@ public abstract class AbstractComponentM
             {
                 throw new IllegalStateException( "Could not obtain lock" );
             }
+            lockingThread = Thread.currentThread();
+            lockingStackTrace = new Exception("Write lock stack trace for thread: " + lockingThread);
         }
         catch ( InterruptedException e )
         {
@@ -199,6 +214,8 @@ public abstract class AbstractComponentM
     final void deescalateLock()
     {
         m_stateLock.deescalate();
+        lockingThread = null;
+        lockingStackTrace = null;
     }
 
     final void checkLocked()
@@ -214,6 +231,18 @@ public abstract class AbstractComponentM
         return m_stateLock.getWriteHoldCount() > 0;
     }
 
+    private void dumpThreads()
+    {
+        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+        StringBuffer b = new StringBuffer( "Thread dump\n" );
+        ThreadInfo[] infos = threadMXBean.dumpAllThreads( threadMXBean.isObjectMonitorUsageSupported(),
threadMXBean.isSynchronizerUsageSupported() );
+        for ( int i = 0; i < infos.length; i++ )
+        {
+            b.append( infos[i] ).append( "\n\n" );
+        }
+        log( LogService.LOG_INFO, b.toString(), null );
+    }
+
 //---------- Component ID management
 
     void registerComponentId()



Mime
View raw message