KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > monitor > support > MonitorSupport


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.monitor.support;
9
10 import test.compliance.monitor.MonitorSUITE;
11
12 public class MonitorSupport
13 {
14    boolean done = false;
15    String last = "set";
16    public synchronized void lock(String who)
17    {
18       if (!done && last.equals(who))
19       {
20          try
21          {
22             wait(MonitorSUITE.MAX_WAIT);
23          }
24          catch (InterruptedException e) {}
25          if (!done && last.equals(who))
26             throw new RuntimeException("-- Time Out --");
27       }
28    }
29    public synchronized void unlock(String who)
30    {
31       if (!done && last.equals(who))
32          throw new RuntimeException("-- Synchronization failure --");
33       last=who;
34       notifyAll();
35    }
36    public synchronized void end()
37    {
38       done = true;
39       notifyAll();
40    }
41 }
42
Popular Tags