Fix concurrency issue in hashmap
This commit is contained in:
parent
0556dfa7af
commit
6586fc438d
|
@ -65,8 +65,8 @@ public class HashMapResourceProvider<T extends IBaseResource> implements IResour
|
||||||
private final Class<T> myResourceType;
|
private final Class<T> myResourceType;
|
||||||
private final FhirContext myFhirContext;
|
private final FhirContext myFhirContext;
|
||||||
private final String myResourceName;
|
private final String myResourceName;
|
||||||
protected Map<String, TreeMap<Long, T>> myIdToVersionToResourceMap = new LinkedHashMap<>();
|
protected Map<String, TreeMap<Long, T>> myIdToVersionToResourceMap = Collections.synchronizedMap(new LinkedHashMap<>());
|
||||||
protected Map<String, LinkedList<T>> myIdToHistory = new LinkedHashMap<>();
|
protected Map<String, LinkedList<T>> myIdToHistory = Collections.synchronizedMap(new LinkedHashMap<>());
|
||||||
protected LinkedList<T> myTypeHistory = new LinkedList<>();
|
protected LinkedList<T> myTypeHistory = new LinkedList<>();
|
||||||
private long myNextId;
|
private long myNextId;
|
||||||
private AtomicLong myDeleteCount = new AtomicLong(0);
|
private AtomicLong myDeleteCount = new AtomicLong(0);
|
||||||
|
@ -188,9 +188,7 @@ public class HashMapResourceProvider<T extends IBaseResource> implements IResour
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized TreeMap<Long, T> getVersionToResource(String theIdPart) {
|
private synchronized TreeMap<Long, T> getVersionToResource(String theIdPart) {
|
||||||
if (!myIdToVersionToResourceMap.containsKey(theIdPart)) {
|
myIdToVersionToResourceMap.computeIfAbsent(theIdPart, t -> new TreeMap<>());
|
||||||
myIdToVersionToResourceMap.put(theIdPart, new TreeMap<>());
|
|
||||||
}
|
|
||||||
return myIdToVersionToResourceMap.get(theIdPart);
|
return myIdToVersionToResourceMap.get(theIdPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,9 +331,7 @@ public class HashMapResourceProvider<T extends IBaseResource> implements IResour
|
||||||
myTypeHistory.addFirst(theResource);
|
myTypeHistory.addFirst(theResource);
|
||||||
|
|
||||||
// Store to ID history map
|
// Store to ID history map
|
||||||
if (!myIdToHistory.containsKey(theIdPart)) {
|
myIdToHistory.computeIfAbsent(theIdPart, t -> new LinkedList<>());
|
||||||
myIdToHistory.put(theIdPart, new LinkedList<>());
|
|
||||||
}
|
|
||||||
myIdToHistory.get(theIdPart).addFirst(theResource);
|
myIdToHistory.get(theIdPart).addFirst(theResource);
|
||||||
|
|
||||||
// Return the newly assigned ID including the version ID
|
// Return the newly assigned ID including the version ID
|
||||||
|
|
Loading…
Reference in New Issue