summaryrefslogtreecommitdiff
path: root/libjava/classpath/testsuite/java.lang/JoinTest.java
diff options
context:
space:
mode:
authorTom Tromey <tromey@gcc.gnu.org>2005-07-16 00:30:23 +0000
committerTom Tromey <tromey@gcc.gnu.org>2005-07-16 00:30:23 +0000
commitf911ba985aa7fe0096c386c5be385ac5825ea527 (patch)
treea0b991cf5866ae1d616639b906ac001811d74508 /libjava/classpath/testsuite/java.lang/JoinTest.java
parent6f4434b39b261de5317dc81ddfdd94d2e1d62b11 (diff)
Initial revision
From-SVN: r102074
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 00000000000..5d5d62d208b
--- /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);
+ }
+ }
+}