Y
yccheok
Hi, may I know is there any technique avaible, for pausing/ resuming
execution of the thread, which is inside while loop, by using tools
from java.util.concurrent.
1) I do not want to use busy pooling, it is ugly and wasting CPU
resource.
2) Is the following a proven bug free method?
public synchronized void pauseWork() {
request = PAUSE;
notify();
}
public synchronized void resumeWork() {
if (request == PAUSE) {
request = RESUME;
notify();
}
}
private void waitIfPauseRequest()
throws InterruptedException {
synchronized (this) {
if (request == PAUSE) {
while (request != RESUME) {
wait();
}
request = NORMAL;
}
}
}
execution of the thread, which is inside while loop, by using tools
from java.util.concurrent.
1) I do not want to use busy pooling, it is ugly and wasting CPU
resource.
2) Is the following a proven bug free method?
public synchronized void pauseWork() {
request = PAUSE;
notify();
}
public synchronized void resumeWork() {
if (request == PAUSE) {
request = RESUME;
notify();
}
}
private void waitIfPauseRequest()
throws InterruptedException {
synchronized (this) {
if (request == PAUSE) {
while (request != RESUME) {
wait();
}
request = NORMAL;
}
}
}