PR target/27599
[official-gcc.git] / libjava / classpath / testsuite / java.lang / JoinTest.java
blob5d5d62d208b20d17fe6f33aca41afd659a878105
1 public class JoinTest
2 implements Runnable
4 public static int count = 0;
6 void send()
7 throws Exception
9 Thread.sleep(2000);
10 System.out.println("PASSED: Sender completed");
12 void receive()
13 throws Exception
15 synchronized(this) {
16 notifyAll();
19 Thread.sleep(5000);
20 count++;
21 System.out.println("PASSED: Receiver completed");
24 public void run()
26 String name = Thread.currentThread().getName();
27 if (name.equals("timer")) {
28 try {
29 Thread.sleep(10000);
30 } catch (InterruptedException e){}
31 System.out.println("FAILED: timer triggered");
32 System.exit(1);
34 try {
35 receive();
36 } catch (Exception e) {
37 System.out.println("FAILED: receiver: " + e);
38 System.exit(1);
41 public static void main(String args[])
43 try {
44 JoinTest sender =
45 new JoinTest();
46 JoinTest receiver =
47 new JoinTest();
48 Thread receiver_thread = new Thread(receiver);
50 /* Make sure the test terminates even if it hangs on network */
51 JoinTest timer = new JoinTest();
52 Thread timer_thread = new Thread(timer, "timer");
53 timer_thread.start();
55 synchronized(receiver) {
56 receiver_thread.start();
57 receiver.wait();
59 try {
60 sender.send();
61 } catch (Exception e) {
62 System.out.println("FAILED: sender: " + e);
63 System.exit(1);
65 receiver_thread.join();
67 if (0 == count)
68 throw new Exception("Nothing received");
70 System.out.println("PASSED: Join send/receive count="+count);
71 System.exit(0);
72 } catch (Exception e) {
73 System.out.println("FAILED: " + e);
74 System.exit(1);