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,41 ----
* 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 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,68 ****
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);
--- 50,70 ----
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 (!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,87 ****
--- 79,93 ----
}
}
static class ThreadOne extends Thread {
public void run() {
+ try {
A();
+ } finally {
+ finished = true;
+ }
}
private void A() {
waitForDump();
B();
}