Java Reference
In-Depth Information
The processing time of a single task includes not only the time to execute the task Run-
nable , but also the time to dequeue the task from the shared work queue. If the work queue
is a LinkedBlockingQueue , the dequeue operation may block less than with a synchron-
ized LinkedList because LinkedBlockingQueue uses a more scalable algorithm, but
accessing any shared data structure fundamentally introduces an element of serialization into
a program.
This example also ignores another common source of serialization: result handling. All useful
computations produce some sort of result or side effect—if not, they can be eliminated as
dead code. Since Runnable provides for no explicit result handling, these tasks must have
some sort of side effect, say writing their results to a log file or putting them in a data struc-
ture. Log files and result containers are usually shared by multiple worker threads and there-
fore are also a source of serialization. If instead each thread maintains its own data structure
for results that are merged after all the tasks are performed, then the final merge is a source
of serialization.
Listing 11.1. Serialized Access to a Task Queue.
Search WWH ::




Custom Search