Skip to contentPackage: Semaphor
Semaphor
Coverage
      1: package basic;
2: 
3: /**
4:  * The Semaphore to lock or unlock a attribute.
5:  * 
6:  * @author HFW410
7:  * 
8:  */
9: public class Semaphor {
10:         /**
11:          * The counter for the semaphore.
12:          */
13:         private Integer count;
14: 
15:         /**
16:          * The constructor for the semaphore.
17:          * 
18:          * @param count
19:          *            the counter for the semaphore.
20:          */
21:         public Semaphor(final Integer count) {
22:                 super();
23:                 this.count = count;
24:         }
25: 
26:         /**
27:          * unlock the attribute.
28:          */
29:         public synchronized void up() {
30:                 this.count++;
31:                 this.notifyAll();
32:         }
33: 
34:         /**
35:          * lock the attribute.
36:          * 
37:          * @throws InterruptedException
38:          *             if it failed.
39:          */
40:         public synchronized void down() throws InterruptedException {
41:•                while (this.count == 0) {
42:                         wait();
43:                 }
44:                 this.count--;
45:         }
46: 
47: }