Let's say I have a parallel card with a high reading level, low write and the need to store application data:
ConcurrentMap<UUID, Data> map = new ConcurrentHashMap<UUID, Data>();
Then, at startup and through user input, data is added to the map:
public void createData(Data newData) { map.put(newId, newData);
If I need to change the data, I must:
A) Make the data class objects immutable and then perform the put operation every time a change is required for the Data object:
public void changeData(UUID oldId, Foo newInfo) { Data oldData = map.get(oldId); Data newData = new Data(oldData, newInfo);
B) Make data class objects mutable but thread safe with mutable fields, atomic links, or trailing parallel fields, and simply modify the object as necessary:
public void changeData(UUID oldId, Foo newInfo) { Data data = map.get(id); data.changeSomething(newInfo); saveToDatabase(data); }
C) None of the above
source share