jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1215493 - /jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
Date Sat, 17 Dec 2011 14:16:57 GMT
Author: pmouawad
Date: Sat Dec 17 14:16:57 2011
New Revision: 1215493

URL: http://svn.apache.org/viewvc?rev=1215493&view=rev
Log:
Added full stacktrace (will be helpful to diagnose not ending threads)

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java?rev=1215493&r1=1215492&r2=1215493&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java Sat Dec 17 14:16:57
2011
@@ -478,12 +478,45 @@ public final class JOrphanUtils {
      */
     public static void displayThreads(boolean includeDaemons) {
         Map<Thread, StackTraceElement[]> m = Thread.getAllStackTraces();
-        for(Thread t : m.keySet()) {
-            boolean daemon = t.isDaemon();
+        String lineSeparator = System.getProperty("line.separator");
+        for(Map.Entry<Thread, StackTraceElement[]> e : m.entrySet()) {
+            boolean daemon = e.getKey().isDaemon();
             if (includeDaemons || !daemon){
-                System.out.println(t.toString()+((daemon ? " (deamon)" : "")));
+            	StringBuilder builder = new StringBuilder();
+            	StackTraceElement[] ste = e.getValue();
+            	for (StackTraceElement stackTraceElement : ste) {
+            		int lineNumber = stackTraceElement.getLineNumber();
+					builder.append(stackTraceElement.getClassName()+"#"+stackTraceElement.getMethodName()+
+							(lineNumber >=0 ? " at line:"+ stackTraceElement.getLineNumber() : "")+lineSeparator);
+				}
+                System.out.println(e.getKey().toString()+((daemon ? " (daemon)" : ""))+",
stackTrace:"+ builder.toString());
             }
         }
     }
+    
+    public static void main(String[] args) {
+		for (int i = 0; i <10; i++) {
+			new Thread(new Runnable() {
+				
+				@Override
+				public void run() {
+					try {
+						Thread.sleep(10000);
+					} catch (InterruptedException e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+				}
+			}).start();
+		}
+		
+		try {
+			Thread.sleep(1000);
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		displayThreads(true);
+	}
 
 }



Mime
View raw message