BigMemory 4.3.10 | Product Documentation | BigMemory Go Developer Guide | Using Explicit Locking | Code Sample for Explicit Locking
 
Code Sample for Explicit Locking
The following is a simple example that shows how to use explicit locking.
String key = "123";
Foo val = new Foo();
cache.acquireWriteLockOnKey(key);
try {
cache.put(new Element(key, val));
} finally {
cache.releaseWriteLockOnKey(key);
}
...sometime later
String key = "123";
cache.acquireWriteLockOnKey(key);
try {
Object cachedVal = cache.get(key).getValue();
cachedVal.setSomething("abc");
cache.put(new Element(key, cachedVal));
} finally {
cache.releaseWriteLockOnKey(key);
}