Reset branch to trunk.
[official-gcc.git] / trunk / libjava / testsuite / libjava.lang / Thread_Monitor.java
blob649a75c762c1d3d70e7f3d297903e38f0103b3cd
1 // Test that monitor locks work and are recursive.
3 class T implements Runnable
5 public int count = 0;
6 Counter c;
8 public T (Counter c)
10 this.c = c;
13 public void run()
15 while (true)
17 // NOTE: double-synchronization here.
18 synchronized (c)
20 if (c.getCount() <= 100000)
21 count++;
22 else
23 break;
29 class Counter
31 int i = 0;
32 public synchronized int getCount ()
34 return ++i;
38 public class Thread_Monitor
40 public static void main(String args[])
42 Counter c = new Counter();
43 T t1 = new T(c);
44 T t2 = new T(c);
46 Thread th1 = new Thread(t1);
47 Thread th2 = new Thread(t2);
48 th1.start();
49 th2.start();
50 try
52 th1.join();
53 th2.join();
55 catch (InterruptedException x)
57 System.out.println("failed: Interrupted");
59 if (t1.count + t2.count == 100000)
60 System.out.println ("ok");
61 else
62 System.out.println ("failed: total count incorrect");