Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java Callable FutureTask Excecuter: How to listen to finished task

I'm quite new to executer services. Liked doing everything myself, but I think it's time to trust these services.

I want to hand by Executer a Runnable. The executer wraps that in a FutureTask and hands it back to me. Now I call poll the done() method. But I would like to be notified when then done() method would return true.

There is a get() method that blocks until the Runnable has finished, but then I would need a extra thread for every job, just to see when it's finished.

Can I hand my executer some extra Callable to get notified about the task finishing?

What's the way to go here? I could add some code to the end of the run method, but then done() might still be false...

like image 748
Franz Kafka Avatar asked Feb 02 '23 17:02

Franz Kafka


1 Answers

ExecutorCompletionService

http://download.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ExecutorCompletionService.html

like image 151
irreputable Avatar answered Feb 05 '23 07:02

irreputable