Java Reference
In-Depth Information
Listing 5.12. Using FutureTask to Preload Data that is Needed Later.
Preloader creates a FutureTask that describes the task of loading product information
from a database and a thread in which the computation will be performed. It provides a
start method to start the thread, since it is inadvisable to start a thread from a constructor
or static initializer. When the program later needs the ProductInfo , it can call get , which
returns the loaded data if it is ready, or waits for the load to complete if not.
Tasks described by Callable can throw checked and unchecked exceptions, and any
code can throw an Error . Whatever the task code may throw, it is wrapped in an Exe-
Search WWH ::




Custom Search