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

后端 未结 3 537
既然无缘
既然无缘 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:45

    if you comment out

        try
        {
            t.join();
        }
        catch (InterruptedException e)
        {
            System.out.println(e.getMessage());
        }
    

    deadlock will not occur...Your thread will run after class load.

提交回复
热议问题