Java Language Executor, ExecutorService and Thread pools Using Thread Pools


Thread Pools are used mostly calling methods in ExecutorService.

The following methods can be used to submit work for execution:

submitExecutes a the submitted work and return a future which can be used to get the result
executeExecute the task sometime in the future without getting any return value
invokeAllExecute a list of tasks and return a list of Futures
invokeAnyExecutes all the but return only the result of one that has been successful (without exceptions)

Once you are done with the Thread Pool you can call shutdown() to terminate the Thread Pool. This executes all pending tasks. To wait for all tasks to execute you can can loop around awaitTermination or isShutdown().