Inspectopedia
 
2024.3

'wait()' not called in loop

Warning
New
Last modified: 03 December 2024

Reports calls to wait() that are not made inside a loop.

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

Example:

Good code should look like this: