You start off on thread 1 (the "main" thread), and start executing the static initializer for the A
class.
Within that static initializer, you then start a new thread (2), which uses something within the A
class. That means that thread 2 needs to wait until the A
class has finished initilaizing before it will proceed, as per section 12.4.2 of the JLS:
If the Class object for C indicates that initialization is in progress for C by some other thread, then release LC and block the current thread until informed that the in-progress initialization has completed, at which time repeat this step.
However, your static initializer for A
waits until thread 2 has completed (by calling join()
) before it completes, leading to deadlock: the static initializer can't complete until thread 2 has completed, and thread 2 can't complete until the static initializer has completed...
Upshot: don't do this :)