Task is to keep track of some running processes. Keeping that information in memory is just fine, so I'm using a concurrent hash map to store that data:
ConcurrentHashMap<String, ProcessMetaData> RUNNING_PROCESSES = new ConcurrentHashMap();
It's all good and fine with safely putting new objects in the map, problem is that state of those processes change so I have to update ProcessMetaData
from time to time. I made ProcessMetaData
immutable and use ConcurrentHashMap
's compute()
method to update values, but now the problem is ProcessMetaData
gets more complicated and keeping it immutable gets hardly manageable. The question is - as long as I only update ProcessMetaData
in atomic (as per javadoc) compute()
method - the object may be mutable and overall things will still be thread-safe? Is my assumption correct?