is the lock even necessary?
No, in your case (to add/remove/get a value) you don't need to use lock. ConcurrentHashMap is designed for such operation. But probably you may change your method "add" in the following manner:
public SomeObject add(String string, PARAMETERS_TO_CONSTRUCT_SomeObject) {
SomeObject result = concurrentHashMap.get(string);
if (result == null) {
result = new SomeObject(PARAMETERS_TO_CONSTRUCT_SomeObject);
SomeObject old = map.putIfAbsent(string, result);
if (old != null) {
result = old;
}
}
return result;
}
This guaranties you always have only one instance of SomeObject associated with the given key and prevents unnecessary instance creation/memory allocation.
does it make any sense to make a ConcurrentHashMap volatile?
I think the best way to publish your ConcurrentHashMap safely in this case is to define it as a final one:
private final ConcurrentHashMap<String, SomeObject> concurrentHashMap = new ConcurrentHashMap<>();