Deadlock caused while creating a Thread in a static block in Java

后端 未结 3 509
既然无缘
既然无缘 2021-01-23 16:07

I was just trying to create a Thread in a static block in Java that caused a deadlock to occur. The code snippet is as follows.

package deadlock;

f         


        
3条回答
  •  离开以前
    2021-01-23 16:42

    In order for the thread to be able to set the static value, the class must be loaded. In order for the class to be loaded, the thread must end (so that the static block completes). That's probably why you have a deadlock.

提交回复
热议问题