21 lines
614 B
Java
21 lines
614 B
Java
// threads/QuittableTask.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
import java.util.concurrent.*;
|
|
|
|
public class QuittableTask implements Runnable {
|
|
private boolean running = true;
|
|
public void quit() { running = false; }
|
|
public boolean running() { return running; }
|
|
@Override
|
|
public void run() {
|
|
while(running)
|
|
try {
|
|
TimeUnit.MILLISECONDS.sleep(100);
|
|
} catch(InterruptedException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|