2
I am porting a Java 8 application to 9, I have some processes that use the concept of Watchdog, who use something similar to:
public synchronized void run() {
until = System.currentTimeMillis() + watchdogParam.getTimeout();
while (!cancelado) {
long delta = until - System.currentTimeMillis();
try {
if (delta > 0) {
wait(delta);
} else {
wait();
}
if (!cancelado && until <= System.currentTimeMillis()) {
fazAlgo();
}
} catch (InterruptedException ex) { }
}
}
Reading the documentation of Thread
, I saw that a new method has been made available: onSpinWait
, where an API note says that the call of this method should be placed where loop is used (in the context of Thread
), but also says that not using it is correct.
That being said, I would like to know what is the need of using this method and whether it is really necessary or not to use it.