Похожие чаты

I have a singleton class with a mutable map as

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?

16 ответов

24 просмотра

Why not just use ConcurrentHashMap or synchronizedMap()?

Roy- Автор вопроса
Manav | avoid unnecessary messaging me
Why not just use ConcurrentHashMap or synchronized...

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.

Manav | avoid unnecessary messaging me
Why won't it require synchronization?

For one thing, it's a final object. Modifications shouldn't be allowed in it.

Roy- Автор вопроса
Velan Chandrasekar
Create a private static final object of the single...

I have no problems with the instance, but the internal variable mutability

Roy
I have no problems with the instance, but the inte...

I got that. The variable is declared inside the singleton, right?

Roy
yes

So, what's the issue?

Roy- Автор вопроса
Roy
@v_lan1337

Yeah.. but if the set is inside the singleton, it still can't be modified, right.

Roy
It can...

If you mean, modifying it with the instance created.. yes, you can. But, you're only worried about concurrent changes, right?

Roy
Yes

Yes, for what?

Roy- Автор вопроса

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
11
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
11
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Карта сайта