diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java index 33529801272..100e8642826 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/HashMapResourceProvider.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.rest.server.provider; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -65,8 +65,8 @@ public class HashMapResourceProvider implements IResour private final Class myResourceType; private final FhirContext myFhirContext; private final String myResourceName; - protected Map> myIdToVersionToResourceMap = new LinkedHashMap<>(); - protected Map> myIdToHistory = new LinkedHashMap<>(); + protected Map> myIdToVersionToResourceMap = Collections.synchronizedMap(new LinkedHashMap<>()); + protected Map> myIdToHistory = Collections.synchronizedMap(new LinkedHashMap<>()); protected LinkedList myTypeHistory = new LinkedList<>(); private long myNextId; private AtomicLong myDeleteCount = new AtomicLong(0); @@ -188,9 +188,7 @@ public class HashMapResourceProvider implements IResour } private synchronized TreeMap getVersionToResource(String theIdPart) { - if (!myIdToVersionToResourceMap.containsKey(theIdPart)) { - myIdToVersionToResourceMap.put(theIdPart, new TreeMap<>()); - } + myIdToVersionToResourceMap.computeIfAbsent(theIdPart, t -> new TreeMap<>()); return myIdToVersionToResourceMap.get(theIdPart); } @@ -333,9 +331,7 @@ public class HashMapResourceProvider implements IResour myTypeHistory.addFirst(theResource); // Store to ID history map - if (!myIdToHistory.containsKey(theIdPart)) { - myIdToHistory.put(theIdPart, new LinkedList<>()); - } + myIdToHistory.computeIfAbsent(theIdPart, t -> new LinkedList<>()); myIdToHistory.get(theIdPart).addFirst(theResource); // Return the newly assigned ID including the version ID