What is the purpose of using synchronized (Thread.currentThread()){…} in Java?

前端 未结 4 987
情书的邮戳
情书的邮戳 2020-12-15 04:42

I faced the following code in our project:

synchronized (Thread.currentThread()){
    //some code
}

I don\'t understand the reason to use s

4条回答
  •  伪装坚强ぢ
    2020-12-15 05:14

    You are implementing a recursive mutex.

    i.e. the same thread can enter the synchronisation block, but not other threads.

提交回复
热议问题