Java Reference
In-Depth Information
The application will allow shared reads but will require exclusive writes. In our
case, the application would have significantly higher throughput for most
caching applications. Relational databases have proven the utility of robust
read / write locks for years. Caching is an example where throughput can be sig-
nificantly improved through the implementation of a read / write lock.
As always, a much better solution than rolling your own is to use a pre-
packaged, respected utility. Many other resources exist for good concurrent
programming in Java. Among the best is a book called Concurrent Program-
ming in Java: Design Principles and Practices. In it, author Doug Lea describes
locking considerations and other techniques for ensuring correctness. His
website, http: // g.oswego.edu / dl / , also includes util.concurrent , a well-
respected collection of utilities for concurrent programming.
5.6
Cooking the Cacheless Cow
This chapter has shown that caching can add a substantial boost to perfor-
mance when applications meet certain criteria. Real-world architectures have
implemented caches on every level, from low-level hardware to operating sys-
tems, networks, and distributed applications. We also know that many applica-
tions neglect this important potential performance boost. The Command
design pattern provides a convenient point to add a cache. This chapter has
presented an unsophisticated cache solution, but many frameworks will build in
command caches over time. Many of the applications that do cache unnecessar-
ily limit throughput by falling into the trap laid by the Synchronized Read /
Write Bottleneck antipattern or other mini-antipatterns defined in this chapter.
5.7
Antipatterns in this chapter
These are the templates for the antipatterns that appear in this chapter. They
provide an excellent summary format and form the basis of the cross-refer-
ences in appendix A.
The Cacheless Cow
R ELATED ANTIPATTERNS : Round-tripping. Poor caching strategies usu-
ally lead to round-tripping and poor performance.
D ESCRIPTION : Caches can be used to provide a significant performance
boost with very little effort, but many developers neglect this basic
enhancement. Most Internet applications take advantage of hardware and
Search WWH ::




Custom Search