In the java web project, I have a set of java bean to cache, so, I use java.lang.HashMap
to store those objects, everytime, client get those object from this map when make a http request. But sometime, this map needs to update a few objects, in the multi-threading environment, I worry about that when one thread updating the object of map, another thread make a get operation to this map, just like this:
Thread-1:
map.put("user:1001", userObject);
Thread-2:
User userObject = map.get("user:1001");
I don't want to use synchronized strategy, so what is the good way to update a map
when a client may get the value from?