test/java/lang/Thread/GenerifyStackTraces.java

Print this page

        

@@ -21,21 +21,21 @@
  * questions.
  */
 
 /*
  * @test
- * @bug     4919105
+ * @bug     4919105 8004177
  * @summary Generified basic unit test of Thread.getAllStackTraces()
  * @author  Mandy Chung
  */
 
 import java.util.*;
 
 public class GenerifyStackTraces {
 
     private static Object go = new Object();
-    private static Object dumpObj = new Object();
+    private static volatile boolean finished = false;
     private static String[] methodNames = {"run", "A", "B", "C", "Done"};
     private static int DONE_DEPTH = 5;
     private static boolean testFailed = false;
 
     private static Thread one;

@@ -50,19 +50,21 @@
 
         Thread dt = new DumpThread();
         dt.setDaemon(true);
         dt.start();
 
+        one.join();
+        dt.join();
         if (testFailed) {
             throw new RuntimeException("Test Failed.");
         }
     }
 
     static class DumpThread extends Thread {
         public void run() {
             int depth = 2;
-            while (true) {
+            while (!finished) {
                 // At each iterator, wait until ThreadOne blocks
                 // to wait for thread dump.
                 // Then dump stack trace and notify ThreadOne to continue.
                 try {
                     sleep(2000);

@@ -77,11 +79,15 @@
         }
     }
 
     static class ThreadOne extends Thread {
         public void run() {
+            try {
             A();
+            } finally {
+                finished = true;
+            }
         }
         private void A() {
             waitForDump();
             B();
         }