Using Thread Pools
suggest changeThread 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().
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents