private static class Node<E> { volatile E item; volatile Node<E> next; /** * Constructs a new node. Uses relaxed write because item can * only be seen after publication via casNext. */ Node(E item) { UNSAFE.putObject(this, itemOffset, item); }
It comes from java.util.concurrent.ConcurrentLinkedQueue.java
What does it mean, relaxed write?
It is a good question. But the clue to understanding this term lies in ... JDK 9, where
sun.misc.Unsafe
has become (or will become - what is more appropriate to say, see here) public API.In JDK 9 the corresponding place, which you refers to, is implemented as follows:
Where
ITEM
is instance ofVarHandle
class which implements similar functionality assun.misc.Unsafe
. Now, we can look at this method's JavaDoc description and find the following:In other words, we can conclude, that relaxed write is the same as plain write access. In other words, I believe that Michael's commentary above is right:
(see the opposite method
setVolatile
which works as if the variable was declaredvolatile
).