diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-07-16 00:30:23 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-07-16 00:30:23 +0000 |
commit | c8875fb97fc03779a5bba09872227b1d08e5d52a (patch) | |
tree | a0b991cf5866ae1d616639b906ac001811d74508 /libjava/classpath/testsuite/java.lang/JoinTest.java | |
parent | c40c1730800ed292b6db39a83d592476fa59623c (diff) | |
download | gcc-c8875fb97fc03779a5bba09872227b1d08e5d52a.tar.gz |
Initial revision
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102074 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/testsuite/java.lang/JoinTest.java')
-rw-r--r-- | libjava/classpath/testsuite/java.lang/JoinTest.java | 77 |
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); + } + } +} |