KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > bank > transaction > implicit > Lock


1 package demo.bank.transaction.implicit;
2
3 public class Lock
4 {
5     private boolean locked;
6
7     public Lock()
8     {
9     locked = false;
10     }
11
12     public synchronized void lock()
13     {
14     while(locked)
15     {
16         try
17         {
18         wait();
19         }
20         catch(InterruptedException JavaDoc ie)
21         {}
22     }
23     locked = true;
24     }
25
26     public synchronized void unlock()
27     {
28     locked = false;
29     notifyAll();
30     }
31 }
32
Popular Tags