I\'m making a program with while loops that execute in this manner:
Busy waits are very expensive. I'd do it this way:
Object LOCK = new Object(); // just something to lock on
synchronized (LOCK) {
while (path != null) {
try { LOCK.wait(); }
catch (InterruptedException e) {
// treat interrupt as exit request
break;
}
}
}
Then when you set path
to null, just call
synchronized (LOCK) {
LOCK.notifyAll();
}
(You can just synchronize on this
if both pieces of code are in the same object.)