Why does java.util.concurrent.ArrayBlockingQueue use 'while' loops instead of 'if' around calls to await()?

前端 未结 5 873
面向向阳花
面向向阳花 2020-11-30 07:56

I have been playing with my own version of this, using \'if\', and all seems to be working fine. Of course this will break down horribly if signalAll() is used instead of s

5条回答
  •  被撕碎了的回忆
    2020-11-30 08:45

    Perhaps missing your point, but the original code uses a while instead of if because there maybe multiple thread listening/consuming the queue...

提交回复
热议问题