Java Reference
In-Depth Information
BetterAttributeStore in Listing 11.5 rewrites AttributeStore to reduce sig-
nificantly the lock duration. The first step is to construct the Map key associated with the
user's location, a string of the form users. name .location . This entails instantiating a
StringBuilder object, appending several strings to it, and instantiating the result as a
String . After the location has been retrieved, the regular expression is matched against the
resulting location string. Because constructing the key string and processing the regular ex-
pression do not access shared state, they need not be executed with the lock held. Better-
AttributeStore factors these steps out of the synchronized block, thus reducing the
time the lock is held.
Search WWH ::




Custom Search