What is the synchronization cost of calling a synchronized method from a synchronized method?

后端 未结 6 1732
梦谈多话
梦谈多话 2021-01-01 13:56

Is there any difference in performance between this

synchronized void x() {
    y();
}

synchronized void y() {
}

and this

         


        
6条回答
  •  遥遥无期
    2021-01-01 14:31

    No difference will be there. Since threads content only to acquire lock at x(). Thread that acquired lock at x() can acquire lock at y() without any contention(Because that is only thread that can reach that point at one particular time). So placing synchronized over there has no effect.

提交回复
热议问题