Your second code snippet is, in my opinion, the best way of thread-safe lazily initializing a singleton. It actually has a pattern name
Initialization-on-demand holder idiom
I would suggest you use it.
Your second code snippet is, in my opinion, the best way of thread-safe lazily initializing a singleton. It actually has a pattern name
Initialization-on-demand holder idiom
I would suggest you use it.