KamilH
03/12/2021, 4:42 PMcoroutines
library, because I think it’s a way most of us doing background job in KN. There are a lot of articles that are trying to explain concurrency topic and this is great. However at the end of the day when you are starting to work with it, you implement simple class that keeps state, state is getting accessed in background thread and you are getting InvalidMutabilityException
. When I get this the only easy way to work around this was to use “AtomicReference”, but later I started thinking if it’s the best solution and it is really not obvious to answers.
Some questions, that it would be great to know answers to:
• How to implement simple in memory cache? With and without Map
(with one value that is nullable and with Map<V,K>
)?
• How to implement a class that does something, keeps internal state, but we don’t know on what thread it is going to be used?
• For collections that keeps state, should we use IsoMutableList
or MutableList<AtomicReference>
? Will they work similarly? What are the performance implications?
• Is StateFlow
useful when it’s about keeping a state?mbonnin
03/12/2021, 4:59 PMIsoMutableList
is certainly a better bet than MutableList<AtomicReference>
. You might want to try a AtomicReference<MutableList>
but that'd certainly require some locking to be really thread safembonnin
03/12/2021, 5:01 PMmbonnin
03/12/2021, 5:04 PMKamilH
03/12/2021, 5:12 PMrusshwolf
03/12/2021, 5:15 PMKamilH
03/12/2021, 5:25 PMnapperley
03/13/2021, 2:45 AMdarkmoon_uk
03/17/2021, 7:07 AMrunBlockingTest
)