Похожие чаты

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 ответов

28 просмотров

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- Автор вопроса

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта