Nested synchronized keyword

后端 未结 6 799
迷失自我
迷失自我 2020-12-29 01:30

I have this code in Java:

    public void doSomeThing() {
        synchronized (this) {
            doSomeThingElse();
        }
    }
    public void doSome         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 02:29

    Lock already obtanied by the thread executing doSomething method, therefore this thread can execute doSomethingElse method.

    You need two lock object to create a deadlock situation. In your case, there is only one, therefore it is impossible to create a deadlock.

提交回复
热议问题