Java Reference
In-Depth Information
applications, there is an obvious task boundary: a single client request. But sometimes good
task boundaries are not quite so obvious, as in many desktop applications. There may also
be exploitable parallelism within a single client request in server applications, as is some-
times the case in database servers. (For a further discussion of the competing design forces in
choosing task boundaries, see [CPJ 4.4.1.1].)
Listing 6.9. Class Illustrating Confusing Timer Behavior.
In this section we develop several versions of a component that admit varying degrees of
concurrency. Our sample component is the page-rendering portion of a browser application,
which takes a page of HTML and renders it into an image buffer. To keep it simple, we as-
sume that the HTML consists only of marked up text interspersed with image elements with
pre-specified dimensions and URLs.
6.3.1. Example: Sequential Page Renderer
The simplest approach is to process the HTML document sequentially. As text markup is
encountered, render it into the image buffer; as image references are encountered, fetch the
image over the network and draw it into the image buffer as well. This is easy to implement
and requires touching each element of the input only once (it doesn't even require buffering
the document), but is likely to annoy the user, who may have to wait a long time before all
the text is rendered.
A less annoying but still sequential approach involves rendering the text elements first, leav-
ing rectangular placeholders for the images, and after completing the initial pass on the doc-
Search WWH ::




Custom Search