My Java app uses a java.util.concurrent.Executors.newCachedThreadPool() to launch a number of different threads that do different kinds of work.
Some of the threads return a value. For these, I am using Future.get() to retrieve the value from the thread.
Other threads don’t return a value that I care about. They are declared to return an Object, and the returned value is always null. For these threads, I am currently calling Future.get() even though there is no value to get. Is that necessary, or is it pointless? My thinking was that perhaps Future.get() notifies the thread pool that I’m done with this thread.
Short answer is no. However, if you want to check that everything completed successfully, Future.get() will let you know if there was an ExecutionException (by throwing it). So I usually call it, even if there is no “result” that I care about. YMMV depending on how you are doing the error handling.
As Tom Anderson mentions,
Callable<Void>is an option to remind people that there is no “result”. But frankly, my Callables meant for an Executor almost always return themselves, so that you can really double check on the results if need be. e.g. (somewhat exaggerated)