* tests/threadInterrupt.java: Added a test showing a bug in the pre-sable
[cacao.git] / tests / threadInterrupt.java
1 public class threadInterrupt {
2         public static class firstthread implements Runnable {
3                 private threadInterrupt s;
4
5                 public firstthread(threadInterrupt s_) {
6                         s = s_;
7                 }
8                 public void run() {
9                         try {
10                                 synchronized (s.o1) {
11                                         System.out.println("first thread!");
12                                         Thread.sleep(500);
13                                         System.out.println("interrupting");
14                                         s.t2.interrupt();
15                                         System.out.println("leaving");
16                                 }
17                         } catch (Exception e) {
18                                 e.printStackTrace();
19                         }
20                 }
21         }
22
23         public static class secondthread implements Runnable {
24                 private threadInterrupt s;
25
26                 public secondthread(threadInterrupt s_) {
27                         s = s_;
28                 }
29                 public void run() {
30                         try {
31                                 Thread.sleep(250);
32                                 synchronized (s.o1) {
33                                         System.out.println("second thread!");
34                                         s.o1.wait();
35                                 }
36                         } catch (Exception e) {
37                                 e.printStackTrace();
38                         }
39                 }
40         }
41
42         public Object o1 = new Object();
43         public Thread t1 = null;
44         public Thread t2 = null;
45
46         public static void main(String args[]) {
47                 System.out.println("should exit with java.lang.InterruptedException");
48                 threadInterrupt s = new threadInterrupt();
49                 firstthread r1 = new firstthread(s);
50                 secondthread r2 = new secondthread(s);
51
52                 s.t1 = new Thread(r1, "a");
53                 s.t2 = new Thread(r2, "b");
54                 s.t1.start();
55                 s.t2.start();
56         }
57 }
58
59 /*
60  * These are local overrides for various environment variables in Emacs.
61  * Please do not remove this and leave it at the end of the file, where
62  * Emacs will automagically detect them.
63  * ---------------------------------------------------------------------
64  * Local variables:
65  * mode: java
66  * indent-tabs-mode: t
67  * c-basic-offset: 4
68  * tab-width: 4
69  * End:
70  * vim:noexpandtab:sw=4:ts=4:
71  */