public class GuardedClass { |
protected boolean cond_ = false; |
protected synchronized void awaitCond() { |
while(!cond) { |
try { wait(); } |
catch(InterrrupedException ex) {} |
} |
} |
public synchronized void guardedAction() { |
awaitCond(); |
//actions |
} |
public synchronized void setCond(boolen cond) { |
cond_ = cond; |
notifyAll(); |
} |
} |