Java Reference
In-Depth Information
6.3.8. Example: A Travel Reservations Portal
The time-budgeting approach in the previous section can be easily generalized to an arbitrary
number of tasks. Consider a travel reservation portal: the user enters travel dates and require-
ments and the portal fetches and displays bids from a number of airlines, hotels or car rental
companies. Depending on the company, fetching a bid might involve invoking a web service,
consulting a database, performing an EDI transaction, or some other mechanism. Rather than
have the response time for the page be driven by the slowest response, it may be preferable to
present only the information available within a given time budget. For providers that do not
respond in time, the page could either omit them completely or display a placeholder such as
“Did not hear from Air Java in time.”
Listing 6.16. Fetching an Advertisement with a Time Budget.
Fetching a bid from one company is independent of fetching bids from another, so fetching
a single bid is a sensible task boundary that allows bid retrieval to proceed concurrently. It
would be easy enough to create n tasks, submit them to a thread pool, retain the Future s,
Search WWH ::




Custom Search