Can a thread call wait() on two locks at once in Java (6)

后端 未结 2 1333
眼角桃花
眼角桃花 2021-01-28 01:58

I\'ve just been messing around with threads in Java to get my head around them (it seems like the best way to do so) and now understand what\'s going on with synchronize, wait()

2条回答
  •  难免孤独
    2021-01-28 02:46

    No, not with a standaad Java lock. Although I guess you could construct such a lock.

    wait should be called within a while loop (wait may spuriously wakeup, and in most situations you would want the loop anyway). So some kind of flag would make more sense.

提交回复
热议问题