if (Thread.interrupted()) {throw something/do something!}
}
*/
package Extensions;
import java.io.*;
public class ConditionVar {
public void condWait(Mutex mutex) {
boolean interrupted = false;
while (true) {
try {
synchronized (this) {
mutex.unlock();
wait();
break;
}
} catch (InterruptedException ie) {
interrupted = true;
}
}
mutex.lock();
if (interrupted)
Thread.currentThread().interrupt();
}
public void condWait(Mutex mutex, long timeout)
boolean interrupted = false;
while (true) {
try {
synchronized (this) {
mutex.unlock();
wait(timeout);
break;
}
} catch (InterruptedException ie) {
interrupted = true;
}
}
mutex.lock();
if (interrupted)
Thread.currentThread().interrupt();
}
public synchronized void condSignal() {
notify();
}
public synchronized void condBroadcast() {
notifyAll();
}
}
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home