Java Reference
In-Depth Information
7.2.4. Example: A One-shot Execution Service
If a method needs to process a batch of tasks and does not return until all the tasks are fin-
ished, it can simplify service lifecycle management by using a private Executor whose
lifetime is bounded by that method. (The invokeAll and invokeAny methods can often
be useful in such situations.)
The checkMail method in Listing 7.20 checks for new mail in parallel on a number of
hosts. It creates a private executor and submits a task for each host: it then shuts down the
executor and waits for termination, which occurs when all the mail-checking tasks have com-
pleted. [4]
Listing 7.18. Producer Thread for IndexingService .
Search WWH ::




Custom Search