Synchronized block and monitor objects

前端 未结 3 514
名媛妹妹
名媛妹妹 2021-02-08 15:19

Hi can someone explain if the in the following code the synchronized code will restrict access to the threads. If yes how is it different from, if we have used \"this\" as a mon

3条回答
  •  一生所求
    2021-02-08 15:55

    The method you wrote will block only if two threads will invoke this method with the exact same msg object.

    If you synchronize on this then it only one thread will be able to invoke the method at a given time.

提交回复
热议问题