01: package snow.concurrent;
02:
03: /** this is part of an interrupatble task.
04: It signal a task that it should stop the evaluation.
05: It is a safe and lazy method to stop a thread, but the thread must
06: programmatically often check if it must stop !
07: */
08: public class Interrupter {
09: private volatile boolean shouldStop = false;
10:
11: public void stopEvaluation() {
12: shouldStop = true;
13: }
14:
15: public boolean getShouldStopEvaluation() {
16: return shouldStop;
17: }
18:
19: /** use this to reset the interrupter.
20: */
21: public void reset() {
22: shouldStop = false;
23: }
24: }
|