Похожие чаты

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

13 просмотров

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

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

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

Скажите, можно ли как-то "переместить" динамический массив из одной переменной в другую? Скажем, переместить из TList<> в TArray<>. Именно переместить, а не скопировать. Если ...
Eugene Krasnikov (ᴊɪɴ x)
36
Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
комрады, че-та лыжы не едут var tmpFont: TFont; begin tmpFont:= TFont.Create; try case rgFontColor.ItemIndex of 0: tmpFont.Color:= clWindowText; 1: tmpFo...
Ed Doc
34
М-да. Почему бы просто со stringlist не работать?
Michael Longneck
18
VIP-310 Set RedStone as the MAIN oracle for BTC and BNB on BNB Chain Summary If passed, this VIP will perform the following actions: - Configure RedStone as the MAIN oracle...
Venus Announcements
1
Интересно, нет ли какого-то способа получить из dll не адрес самой метки, а адрес со смещением?
The Bird of Hermes
54
monero is the only tool for privacy and currency . why would we destroy it?
😎
13
🔍 Launch of Sentinel dVPN's Native Explorer 🎉 The Sentinel Growth DAO is thrilled to announce the launch of Sentinel dVPN's new native blockchain explorer! Now anyone can div...
Joey | BadgerBite Joeyy
1
Можно вообще написать: Person fName' lName' age'. Тогда действительно имена полей потребуются лишь в строковом виде, чтобы эти fName' и т.д. достать :-) Но разве для этого нуж...
Михаил
8
Whoa, did you guys see this FUNToken Seed Grant announcement? 💸
Noah Noure
37
Карта сайта