Mutithreading with System.out.format and System.out.println

前端 未结 4 1448
梦毁少年i
梦毁少年i 2021-01-14 16:14

I came across this example on Oracle\'s Java Tutorial describing Deadlock in multi threading scenarios.

So in this example I made following change at line 17 and lin

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 16:40

    The deadlock is not dependent on the println function at all. It's caused by the two threads trying to access each other, and locking on each other.

    The change from format to println will have introduced sufficient latency in the program to allow the threads to lock each other without colliding, i.e., deadlocking. So you haven't really fixed it; you've just added some latency that means the threads don't deadlock.

提交回复
热议问题