I have data which need to be updated in concurrent manner. This data lives in PlayFramework as a Singleton Object. Would using AKKA to update this data better in this situation or should I be using STM? They both seems to be doing the same thing so I was wondering which is better.
What's the difference between these two solutions in terms of shared state concurrency.
Thanks
STM allows exclusive writes but many reads where Actors only allows single reads or writes at a time. So when you're in the situation where you want multiple threads to read the shared state concurrently and this operation is rapid, STM is better suited than the Actors.
Play is built on Akka so you've got the advantage that you can start using it immediately. There is no shared data between actors. Instead data (aka messages) are passed from one Actor to another. Message data should be immutable to further achieve the goal of preventing shared mutable state.
You could have a singleton actor that retains internally any state and any access to it achieved with an "ask" request (based on a Future). Therefore the Actor becomes the gate keeper to that singleton data and enforces serial access to it via the messaging system.
I cannot comment about STM and therefore may sound a little biased!
Cheers,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With