Thread safety of static blocks in Java Thread safety of static blocks in Java multithreading multithreading

Thread safety of static blocks in Java


If the first thread hasn't finished initializing SomeClass, the second thread will block.

This is detailed in the Java Language Specification in section 12.4.2.


Static class initialization is guaranteed to be thread-safe by Java.


watch out that you dont call code that require the lock for the class being initialized - it will deadlock. see this blog post: http://ramblingabout.wordpress.com/2008/04/10/deadlock-quiz-the-answer/