Thread safe map which preserves the insertion order

collections, scala, thread-safety

Solution

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

Problem

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?

Original source