Inspectopedia
 
2024.3

'await()' not called in loop

Warning
New
Last modified: 03 December 2024

Reports java.util.concurrent.locks.Condition.await() not being called inside a loop.

await() and related methods are normally used to suspend a thread until some condition becomes true. As the thread could have been woken up for a different reason, the condition should be checked after the await() call returns. A loop is a simple way to achieve this.

Example:

Good code should look like this: