summaryrefslogtreecommitdiff
path: root/libjava/classpath/testsuite/java.lang/ThreadTest.java
blob: cade822ec2a41083ab3765209b4811173ffef69c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.lang.*;

/* Simple producer/consumer thread test. */

public class ThreadTest implements Runnable {
 
  static String threadName = "Running thread";
  static int count = 0;
  static int max = 4; // XXX Seem to fail when >4 on kaffe 0.9.0

  public void run() {
    if (! Thread.currentThread().isAlive() ) {
      System.out.println("FAILED: isAlive() false in new thread!");
    } else {
      System.out.println("PASSED: isAlive() working in new thread");
    }
    while (0 <= count && count <= max) {
      count ++;
    }
  }

  public static void main (String args[]) {
    try {
      if (! Thread.currentThread().isAlive() ) {
	System.out.println("FAILED: isAlive() false in initial thread!");
      } else {
	System.out.println("PASSED: isAlive() working in initial thread");
      }
      ThreadTest test = new ThreadTest();

      Thread testThread = new Thread(test, threadName);

      testThread.setDaemon(true);
      testThread.start();

      Thread.currentThread().sleep(3000);

      if (count < max) {
	System.out.println("FAILED: unable to run new thread");
      } else {	
	System.out.println("PASSED: Theads worked");
      }
      System.exit(0);
    } catch (Exception e) {
      System.out.println("FAILED: "+e);
    }
  }
}