01: /**
02: * $Id: LockWithMemory.java,v 1.5 2002/07/19 18:36:56 davechiu Exp $
03: * Copyright 2002 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.common.util;
14:
15: import java.lang.InterruptedException;
16:
17: public class LockWithMemory {
18: private boolean signalled = false;
19:
20: public synchronized void waitFor() throws InterruptedException {
21: waitFor(0, 0);
22: }
23:
24: public synchronized void waitFor(long timeout)
25: throws InterruptedException {
26: waitFor(timeout, 0);
27: }
28:
29: public synchronized void waitFor(long timeout, int nanos)
30: throws InterruptedException {
31: if (!signalled) {
32: wait(timeout, nanos);
33: }
34: signalled = false;
35: }
36:
37: public synchronized void signal() {
38: notify();
39: signalled = true;
40: }
41:
42: }
|