As was mentioned by AlexIv in his answer, there's a trait you can mix in if you want thread safety. There's another way though:
val synchronizedMap = new scala.collection.mutable.LinkedHashMap[String, Any]() with scala.collection.mutable.SynchronizedMap[String, Any]
As was mentioned by AlexIv in his answer, there's a trait you can mix in if you want thread safety. There's another way though:
val synchronizedMap = new scala.collection.mutable.LinkedHashMap[String, Any]() with scala.collection.mutable.SynchronizedMap[String, Any]
That should give you the map with synchronization on each accessmap with synchronization on each access. Easy, but might not meet the performance requirements. If so, it would be probably easier to create a custom class extending the LinkedHashMap
, mixing in the concurrent.Map
trait (as was suggested) and provide the implementation of relevant methods, i.e: putIfAbsent
, remove
replace
(2 overloads).