Java Reference
In-Depth Information
Listing 5.20. Factorizing Servlet that Caches Results Using Memoizer .
Summary of Part I
We've covered a lot of material so far! The following “concurrency cheat sheet” summarizes
the main concepts and rules presented in Part I .
It's the mutable state, stupid. [1]
All concurrency issues boil down to coordinating access to mutable state. The less
mutable state, the easier it is to ensure thread safety.
Make fields final unless they need to be mutable.
Immutable objects are automatically thread-safe.
Immutable objects simplify concurrent programming tremendously. They are sim-
pler and safer, and can be shared freely without locking or defensive copying.
Encapsulation makes it practical to manage the complexity.
You could write a thread-safe program with all data stored in global variables, but
Search WWH ::




Custom Search