OnJava8-Examples/threads/QuittableTask.java
2016-09-23 13:23:35 -06:00

21 lines
596 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://OnJava8.com 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);
}
}
}