fix concurrent modification exceptions in local cache

This commit is contained in:
fjy 2014-04-08 16:23:24 -07:00
parent 7c90a0fb96
commit dd8e9e2930
1 changed files with 11 additions and 5 deletions

View File

@ -77,7 +77,10 @@ public class MapCache implements Cache
@Override @Override
public byte[] get(NamedKey key) public byte[] get(NamedKey key)
{ {
final byte[] retVal = baseMap.get(computeKey(getNamespaceId(key.namespace), key.key)); final byte[] retVal;
synchronized (clearLock) {
retVal = baseMap.get(computeKey(getNamespaceId(key.namespace), key.key));
}
if (retVal == null) { if (retVal == null) {
missCount.incrementAndGet(); missCount.incrementAndGet();
} else { } else {
@ -110,7 +113,9 @@ public class MapCache implements Cache
byte[] idBytes; byte[] idBytes;
synchronized (namespaceId) { synchronized (namespaceId) {
idBytes = getNamespaceId(namespace); idBytes = getNamespaceId(namespace);
if(idBytes == null) return; if (idBytes == null) {
return;
}
namespaceId.remove(namespace); namespaceId.remove(namespace);
} }
@ -150,7 +155,8 @@ public class MapCache implements Cache
return retVal; return retVal;
} }
public boolean isLocal() { public boolean isLocal()
{
return true; return true;
} }
} }