Java Reference
In-Depth Information
All concurrent applications have some sources of serialization; if you think yours does not,
look again.
11.2.1. Example: Serialization Hidden in Frameworks
To see how serialization can be hidden in the structure of an application, we can compare
throughput as threads are added and infer differences in serialization based on observed dif-
ferences in scalability. Figure 11.2 shows a simple application in which multiple threads re-
peatedly remove an element from a shared Queue and process it, similar to Listing 11.1 . The
processing step involves only thread-local computation. If a thread finds the queue is empty,
it puts a batch of new elements on the queue so that other threads have something to process
on their next iteration. Accessing the shared queue clearly entails some degree of serializa-
tion, but the processing step is entirely parallelizable since it involves no shared data.
Figure 11.2. Comparing Queue Implementations.
The curves in Figure 11.2 compare throughput for two thread-safe Queue implementations:
a LinkedList wrapped with synchronizedList , and a Concur-
rentLinkedQueue . The tests were run on an 8-way Sparc V880 system running Solaris.
While each run represents the same amount of “work”, we can see that merely changing
queue implementations can have a big impact on scalability.
The throughput of ConcurrentLinkedQueue continues to improve until it hits the num-
ber of processors and then remains mostly constant. On the other hand, the throughput of the
Search WWH ::




Custom Search