aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/testsuite/java.lang/JoinTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/testsuite/java.lang/JoinTest.java')
-rw-r--r--libjava/classpath/testsuite/java.lang/JoinTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/libjava/classpath/testsuite/java.lang/JoinTest.java b/libjava/classpath/testsuite/java.lang/JoinTest.java
new file mode 100644
index 0000000..5d5d62d
--- /dev/null
+++ b/libjava/classpath/testsuite/java.lang/JoinTest.java
@@ -0,0 +1,77 @@
+public class JoinTest
+ implements Runnable
+{
+ public static int count = 0;
+
+ void send()
+ throws Exception
+ {
+ Thread.sleep(2000);
+ System.out.println("PASSED: Sender completed");
+ }
+ void receive()
+ throws Exception
+ {
+ synchronized(this) {
+ notifyAll();
+ }
+
+ Thread.sleep(5000);
+ count++;
+ System.out.println("PASSED: Receiver completed");
+ }
+
+ public void run()
+ {
+ String name = Thread.currentThread().getName();
+ if (name.equals("timer")) {
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e){}
+ System.out.println("FAILED: timer triggered");
+ System.exit(1);
+ }
+ try {
+ receive();
+ } catch (Exception e) {
+ System.out.println("FAILED: receiver: " + e);
+ System.exit(1);
+ }
+ }
+ public static void main(String args[])
+ {
+ try {
+ JoinTest sender =
+ new JoinTest();
+ JoinTest receiver =
+ new JoinTest();
+ Thread receiver_thread = new Thread(receiver);
+
+ /* Make sure the test terminates even if it hangs on network */
+ JoinTest timer = new JoinTest();
+ Thread timer_thread = new Thread(timer, "timer");
+ timer_thread.start();
+
+ synchronized(receiver) {
+ receiver_thread.start();
+ receiver.wait();
+ }
+ try {
+ sender.send();
+ } catch (Exception e) {
+ System.out.println("FAILED: sender: " + e);
+ System.exit(1);
+ }
+ receiver_thread.join();
+
+ if (0 == count)
+ throw new Exception("Nothing received");
+
+ System.out.println("PASSED: Join send/receive count="+count);
+ System.exit(0);
+ } catch (Exception e) {
+ System.out.println("FAILED: " + e);
+ System.exit(1);
+ }
+ }
+}