Java Reference
In-Depth Information
Moving the I/O from many request-processing threads to a single logger thread is similar to
the difference between a bucket brigade and a collection of individuals fighting a fire. In the
“hundred guys running around with buckets” approach, you have a greater chance of conten-
tion at the water source and at the fire (resulting in overall less water delivered to the fire),
plus greater inefficiency because each worker is continuously switching modes (filling, run-
ning, dumping, running, etc.). In the bucket-brigade approach, the flow of water from the
source to the burning building is constant, less energy is expended transporting the water to
the fire, and each worker focuses on doing one job continuously. Just as interruptions are dis-
ruptive and productivity-reducing to humans, blocking and context switching are disruptive
to threads.
Summary
Because one of the most common reasons to use threads is to exploit multiple processors, in
discussing the performance of concurrent applications, we are usually more concerned with
throughput or scalability than we are with raw service time. Amdahl's law tells us that the
scalability of an application is driven by the proportion of code that must be executed seri-
ally. Since the primary source of serialization in Java programs is the exclusive resource lock,
scalability can often be improved by spending less time holding locks, either by reducing
lock granularity, reducing the duration for which locks are held, or replacing exclusive locks
with nonexclusive or nonblocking alternatives.
Search WWH ::




Custom Search