I try to avoid vars in my code where possible for easier multithreading. However there is one line of code that starts:
val positions: Hashtable[String, String] ...
I’m wondering does the val make things automagically thread safe or are there further details that I need to worry about?
By prefixing
positionswith avalyou make it immutable. By “it” I mean the reference to theHashtableand not theHashtableitself and therefore by “immutable” I mean you cannot assign anotherHashtabletopositions.So the
Hashtableitself can change over time, butpositionswill always point to it. Nothing is automagically threadsafe.