While learning Java 9 features I came across a new method of Thread
class, called onSpinWait. As per javadocs, this method is used for this:
I just want to add my 2 cents after reading the document and the source code for it. This method might trigger some optimizations and might not - so care must be taken - you can't really rely on it - since this a hint
to the CPU
more than demand, probably there's no initial relying whatsoever either way... Meaning that it's actual source code looks like this:
@HotSpotIntrinsicCandidate
public static void onSpinWait() {}
What this actually means is that this method is basically a NO-OP until it hits the c2 compiler
in the JIT
, according to this