Question About Deadlock Situation in Java

前端 未结 6 2286
鱼传尺愫
鱼传尺愫 2020-12-08 12:06

I\'m learning about deadlocks in Java, and there\'s this sample code from Sun\'s official tutorial:

Alphonse and Gaston are friends, and great belie

6条回答
  •  盖世英雄少女心
    2020-12-08 12:50

    Locks are held on Java objects, not java methods. So when synchronized is used on a method, it locks the "this" object. In the case of a static method, it locks the class object.

    You can explicitly specify the monitor object by using synchronized ( object ) { }

提交回复
热议问题