I'm porting a Java 8 to 9 application, I have some processes that use the Watchdog concept, which 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 Thread
documentation, 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 there is looping (in the context of Thread
), but also says not to use it is correct.
That's right, I'd like to know what you need to use this method and whether or not it's really necessary to use it.