FELIX-3862 add thread dump on lock timeout
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1437107 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/pom.xml b/scr/pom.xml
index 0ae4a5b..409e52c 100644
--- a/scr/pom.xml
+++ b/scr/pom.xml
@@ -201,6 +201,12 @@
<version>1.0.0</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-annotations</artifactId>
+ <version>1.10-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
<directory>${bundle.build.name}</directory>
@@ -308,7 +314,7 @@
Ensure not using too recent Java API
- Ensure Java 5 API
-->
- <plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.7</version>
@@ -375,7 +381,7 @@
<exclude>**/components/**</exclude>
</excludes>
<includes>
- <include>**/integration/**</include>
+ <include>**/integration/*</include>
</includes>
</configuration>
</plugin>
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
index fd48364..b9d7029 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
@@ -170,6 +170,7 @@
{
if (!m_stateLock.tryLock( m_timeout, TimeUnit.MILLISECONDS ) )
{
+ dumpThreads();
throw new IllegalStateException( "Could not obtain lock" );
}
}
@@ -189,6 +190,19 @@
{
return m_stateLock.getHoldCount() > 0;
}
+
+ private void dumpThreads()
+ {
+ try
+ {
+ String dump = new ThreadDump().call();
+ log( LogService.LOG_ERROR, dump, null );
+ }
+ catch ( Throwable t )
+ {
+ log( LogService.LOG_ERROR, "Could not dump threads", t );
+ }
+ }
//service event tracking
void tracked( int trackingCount )
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ThreadDump.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ThreadDump.java
new file mode 100644
index 0000000..89b03f8
--- /dev/null
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ThreadDump.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.impl.manager;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.util.concurrent.Callable;
+
+import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
+
+public class ThreadDump implements Callable<String>
+{
+
+ @IgnoreJRERequirement
+ public String call() throws Exception
+ {
+ 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++ )
+ {
+ ThreadInfo ti = infos[i];
+ b.append( "\n\nThreadId: " ).append( ti.getThreadId() ).append( " : name: " ).append( ti.getThreadName() ).append( " State: " ).append( ti.getThreadState() );
+ b.append( "\n LockInfo: " ).append( ti.getLockInfo() ).append( " LockOwnerId: " ).append( ti.getLockOwnerId() ).append( " LockOwnerName: ").append( ti.getLockOwnerName() );
+ StackTraceElement[] stackTrace = ti.getStackTrace();
+ for (int j = 0; j < stackTrace.length; j++ )
+ {
+ b.append( "\n " ).append( stackTrace[j] );
+ }
+ }
+ return b.toString();
+ }
+
+}