Is there a join()-like method for threads that have been executed through the ThreadPoolExecutor?
If I submit a few Callables to the executor instead and use the get() method on the Futures that they return, will I get similar behavior to a Thread.join()?
They are similar in the sense they both
Thread#join()andFuture#get()will block until the thread/cllable is finished. In theThread#join()case, the call returns when the thread dies. No result is returned. In theFuture#get()case, it will return when the callable is finished executing its task, but the executing thread will not die (it’s usually part of a thread pool, so it will make itself available back to the pool).If these tasks that you submit to the ExecuterService are mission-critical, it is good practice to add a shutdown hook to your application that calls
threadPool.shutdown()to allow for a graceful completion of all running threads, and waits forthreadPool.isTerminated()to become true, or waits forthreadPool.awaitTermination(max time before force shutdown)to return.