While loop spins on field
while loops, which spin on the value of a non-
volatile field, waiting for it to be changed by another thread.
In addition to being potentially extremely CPU intensive when little work is done inside the loop, such loops likely have different semantics than intended. The Java Memory Model allows that loop to never complete even if another thread changes the field's value.
Additionally since Java 9, calling
Thread.onSpinWait() inside spin loop on a
volatile field is recommended, which may significantly improve performance on some hardware.
Use the checkbox below to have this inspection report only empty
Only warn if loop is empty
IntelliJ IDEA 2023.3, Qodana for JVM 2023.3