Using Thread Pools

suggest change

Thread pools are used mostly by calling methods in ExecutorService.

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

Method Description
submit Submits the work for execution and returns a Future that can be used to get the result
execute Submits the task for execution sometime in the future and returns no value
invokeAll Executes a list of tasks and returns a list of Futures
invokeAny Executes the given tasks but returns only the result of one that completed successfully (without throwing); the others are cancelled

Once you are done with the thread pool you can call shutdown() to terminate it. This executes all pending tasks. To wait for all tasks to finish you can loop around awaitTermination or isTerminated().

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents