Reputation: 3405
In my Scala application I need to use several Maps and Lists which gets updated very often. Are there any thread safe collections in Scala which maintain the insertion order?
Upvotes: 4
Views: 9779
Reputation: 21547
Yes, there is a trait in the scala.collection.concurrent
package: concurrent.Map it's just a trait, so just mixin this trait into your Map and it would become thread-safe.
If you need a good concurrent map, try google's ConcurrentLinkedHashMap (last release 2015) and convert it to Scala Map using Scala/Java converter, that will give more performance that mixin SynchronizedMap
. For example my favourite Spray toolkit, use it as a core structure for implmenting it's caching module. As you can see, spray is the fastest Scala web toolkit
Upvotes: 5