Java - Syncronized Thread - Output in wrong order

前端 未结 3 1587
傲寒
傲寒 2021-01-19 06:40

I\'m reading Java The Complete Reference(9th Edition) after year of fooling around with Java. Been happy with the book so far but I now have a really strange problem with sy

3条回答
  •  有刺的猬
    2021-01-19 07:23

    When multiple threads are waiting on a lock, there is no guarantee as to which thread the lock will be given once its released. The docs does not specify how this order is handled, but its also not random. I cant say for certain, but it seems the default implementation gives the lock in a LIFO style (Last in first out) and thats why world is outputted first. Give it a try with some more objects.

提交回复
热议问题