I have gone through the below links Problem with synchronizing on String objects? and http://illegalargumentexception.blogspot.com/2008/04/java-synchronizing-on-transient-id.html
Now my question:
- I have a map where userid and a list of some properties are maintained
- when we come across new userid we will create an entry in the map
- if the userid is already present we will add some properties to the value
instead of synchronizing on the whole map, we tried to synchronize on the userid and that results in some random behavior, if we use intern() it works the approach in the second link also works
Questions:
- in the second approach we are still locking the whole map when getting key
- is there some other way of synchronization so that the map access is synchronized based on userid alone
- what is the best way to do this?