I'm trying to implement a sample application to test Callable
and ExecutorService
interfaces.
In my app I have declared:
ExecutorService exSvc = Executors.newSingleThreadExecutor();
Then:
Future<Integer> test = exSvc.submit(
new Callable<Integer>() {
public Integer call() {
for(int i = 0; i < 1000; i++){
System.out.println(i);
}
return 1;
}
});
Now I'm trying to stop the process before it terminate, I'm using exSvc.shutdownNow()
but it doesn't work.
To stop gracefully a classical Thread
I usually use some kind of condition variable. Which is a common approach to follow with ExecutorService
?