a instance variable inside it. I am using the map as a cache. This map can be updated asynchronously based on some external events. Is there a design pattern to prevent concurrency issues arising out of the updates?
Why not just use ConcurrentHashMap or synchronizedMap()?
So it's not a simple cache. the map has <String, Set<String>>. In my case, the Set<String> is mutated
Create a private static final object of the singleton class & return it via getInstance() method. It is mentioned that this won't require synchronization. Not sure if it's only for read, or for read/write. You can test it.
Why won't it require synchronization?
For one thing, it's a final object. Modifications shouldn't be allowed in it.
I have no problems with the instance, but the internal variable mutability
I got that. The variable is declared inside the singleton, right?
So, what's the issue?
Yeah.. but if the set is inside the singleton, it still can't be modified, right.
If you mean, modifying it with the instance created.. yes, you can. But, you're only worried about concurrent changes, right?
Yes, for what?
the latter
Обсуждают сегодня