test/java/lang/Thread/GenerifyStackTraces.java

Print this page

        

*** 21,41 **** * questions. */ /* * @test ! * @bug 4919105 * @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 String[] methodNames = {"run", "A", "B", "C", "Done"}; private static int DONE_DEPTH = 5; private static boolean testFailed = false; private static Thread one; --- 21,40 ---- * questions. */ /* * @test ! * @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 String[] methodNames = {"run", "A", "B", "C", "Done"}; private static int DONE_DEPTH = 5; private static boolean testFailed = false; private static Thread one;
*** 46,68 **** } one = new ThreadOne(); one.start(); ! Thread dt = new DumpThread(); ! dt.setDaemon(true); dt.start(); if (testFailed) { throw new RuntimeException("Test Failed."); } } static class DumpThread extends Thread { public void run() { int depth = 2; ! while (true) { // At each iterator, wait until ThreadOne blocks // to wait for thread dump. // Then dump stack trace and notify ThreadOne to continue. try { sleep(2000); --- 45,74 ---- } one = new ThreadOne(); one.start(); ! DumpThread dt = new DumpThread(); dt.start(); + try { + one.join(); + }finally { + dt.shutdown(); + } + if (testFailed) { throw new RuntimeException("Test Failed."); } } static class DumpThread extends Thread { + private volatile boolean finished = false; + public void run() { int depth = 2; ! 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);
*** 73,82 **** --- 79,93 ---- e.printStackTrace(); testFailed = true; } } } + + public void shutdown() throws InterruptedException { + finished = true; + this.join(); + } } static class ThreadOne extends Thread { public void run() { A();