jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1215478 - in /jmeter/trunk: src/core/org/apache/jmeter/JMeter.java src/jorphan/org/apache/jorphan/util/JOrphanUtils.java xdocs/changes.xml
Date Sat, 17 Dec 2011 12:32:24 GMT
Author: sebb
Date: Sat Dec 17 12:32:23 2011
New Revision: 1215478

URL: http://svn.apache.org/viewvc?rev=1215478&view=rev
Log:
Bug 52346 - Shutdown detects if there are any non-daemon threads left which prevent JVM exit

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
    jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java?rev=1215478&r1=1215477&r2=1215478&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/JMeter.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/JMeter.java Sat Dec 17 12:32:23 2011
@@ -929,6 +929,7 @@ public class JMeter implements JMeterPlu
             long now = System.currentTimeMillis();
             println("Tidying up ...    @ "+new Date(now)+" ("+now+")");
             println("... end of run");
+            checkForRemainingThreads();
         }
 
         public void testStarted(String host) {
@@ -964,6 +965,7 @@ public class JMeter implements JMeterPlu
             }
             ClientJMeterEngine.tidyRMI(log);
             println("... end of run");
+            checkForRemainingThreads();
         }
 
         /**
@@ -972,6 +974,30 @@ public class JMeter implements JMeterPlu
         public void testIterationStart(LoopIterationEvent event) {
             // ignored
         }
+
+        /**
+         * Runs daemon thread which waits a short while; 
+         * if JVM does not exit, lists remaining non-daemon threads on stdout.
+         */
+        private void checkForRemainingThreads() {
+            Thread daemon = new Thread(){
+                @Override
+                public void run(){
+                    try {
+                        Thread.sleep(2000); // Allow enough time for JVM to exit
+                    } catch (InterruptedException ignored) {
+                    }
+                    // This is a daemon thread, which should only reach here if there are
other
+                    // no-daemon threads still active
+                    System.out.println("JVM did not exit; following threads are still running
(DestroyJavaVM is OK):");
+                    JOrphanUtils.displayThreads(false);
+                }
+
+            };
+            daemon.setDaemon(true);
+            daemon.start();
+        }
+
     }
 
     private static void println(String str) {

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=1215478&r1=1215477&r2=1215478&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 12:32:23
2011
@@ -25,6 +25,7 @@ import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.StringTokenizer;
 
 /**
@@ -467,4 +468,22 @@ public final class JOrphanUtils {
         }
         return length - remaining;
     }
+
+    /**
+     * Display currently running threads on system.out
+     * This may be expensive to run.
+     * Mainly designed for use at the end of a non-GUI test to check for threads that might
prevent the JVM from exitting.
+     * 
+     * @param includeDaemons whether to include daemon threads or not.
+     */
+    public static void displayThreads(boolean includeDaemons) {
+        Map<Thread, StackTraceElement[]> m = Thread.getAllStackTraces();
+        for(Thread t : m.keySet()) {
+            boolean daemon = t.isDaemon();
+            if (includeDaemons || !daemon){
+                System.out.println(t.toString()+((daemon ? " (deamon)" : "")));
+            }
+        }
+    }
+
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1215478&r1=1215477&r2=1215478&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Dec 17 12:32:23 2011
@@ -236,6 +236,7 @@ Loads any additional properties found in
 <li>Bug 50086 - Password fields not Hidden in JMS Publisher, JMS Subscriber, Mail Reader
sampler, SMTP sampler and Database Configuration</li>
 <li>Added DiskStore remote sample sender: like Hold, but saves samples to disk until
end of test.</li>
 <li>Bug 52333 - Reduce overhead in calculating SampleResult#nanoTimeOffset</li>
+<li>Bug 52346 - Shutdown detects if there are any non-daemon threads left which prevent
JVM exit.</li>
 </ul>
 
 <h2>Non-functional changes</h2>



Mime
View raw message