How to handle concurrent access to a Scala collection?

后端 未结 4 1938
悲哀的现实
悲哀的现实 2021-01-04 11:11

I have an Actor that - in its very essence - maintains a list of objects. It has three basic operations, an add, update and a remove (where sometimes the remove is called fr

4条回答
  •  时光说笑
    2021-01-04 11:41

    What collection type should I use in a concurrent access situation, and how is it used?

    See @hbatista's answer.

    Is an Actor actually a multithreaded entity, or is that just my wrong conception and does it process messages one at a time in a single thread

    The second (though the thread on which messages are processed may change, so don't store anything in thread-local data). That's how the actor can maintain invariants on its state.

提交回复
热议问题