Yurttas/PL/OOL/Java/F/07/03/NotifyUtil.java
Jump to navigation
Jump to search
1/**
2 * Copyright(C) 1998
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 1998.
11 * @author : Salih Yurttas.
12 */
13
14
15public class NotifyUtil {
16
17 private boolean value = false;
18
19 private Object valueLock = new Object();
20
21 public void waitToProceed() {
22 System.out.println("Sleeper : Entering wait to proceed");
23
24 try {
25 synchronized(valueLock) {
26 while(!value)
27 valueLock.wait();
28 }
29 }
30 catch(InterruptedException waitExcept) {
31 System.out.println("Interrupted while waiting");
32 }
33
34 System.out.println("Sleeper : Exiting wait to proceed");
35 }
36
37 public void proceed() {
38 System.out.println("Waker : Entering proceed");
39
40 synchronized(valueLock) {
41 value=true;
42 valueLock.notify();
43 }
44
45 System.out.println("Waker : Exiting proceed");
46 }
47
48}