"scala - mutable thread safe collections" Code Answer

  1. you're duplicating topics....
  2. 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 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).

By iamalismith on May 27 2022

Answers related to “scala - mutable thread safe collections”

Only authorized users can answer the Search term. Please sign in first, or register a free account.