Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 21
    If you can stand a bit more work, use the synchronized method on the mutable collection directly where you need thread safety. It'll save you the performance hit that this mixin brings. E.g. someMap.synchronized { someMap += ("someKey", "anyValue") }
    – tysonjh
    Commented Mar 6, 2014 at 14:32
  • 12
    For anyone new viewing this, the SynchronizedMap trait has been deprecated as not safe enough. Recommends using Java thread safe collections. Commented Aug 20, 2015 at 1:20
  • 1
    It's a compiler warning when you build after mixing in this trait - not sure about a link Commented Oct 10, 2015 at 19:34
  • 4
    @Gepp: scala-lang.org/api/2.12.3/scala/collection/mutable/…: "(Since version 2.11.0) Synchronization via traits is deprecated as it is inherently unreliable. Consider java.util.concurrent.ConcurrentHashMap as an alternative." Commented Nov 8, 2017 at 22:13
  • 3
    TrieMap is mutable, thread-safe, lock-free, and is not deprecated
    – ianpojman
    Commented Nov 5, 2020 at 23:05