Are Java static initializers thread safe?

Yes, Java static initializers are thread safe (use your first option).

However, if you want to ensure that the code is executed exactly once you need to make sure that the class is only loaded by a single class-loader. Static initialization is performed once per class-loader.

Leave a Comment