What is the proper way to initialize singleton element in a thread safe way in Scala?
问题 I've faced a problem of initializing singleton element in a thread safe way in Scala. Usually companion object is used. But this time I need to pass a config object to initializer. Calling some init function of companion object either not thread safe, or leads to locks, that looks kind of low level for Scala (may be I'm not right). The thing I came up with is a cache. Calling cache with the same argument helps to initialize it exactly once. But the strange thing for me is that I have to use