Java AtomicLong lazySet() Method

The lazySet() method of Java AtomicLong class sets the value to newValue. It has the memory effects of writing (assigning) a volatile variable except that it permits reorderings with subsequent (but not previous) memory actions that do not themselves impose reordering constraints with ordinary non-volatile writes. Among other usage contexts, lazySet may apply when nulling out, for the sake of garbage collection, a reference that is never accessed again.

Syntax

Parameters

newValue - the new value

Example 1

Test it Now

Output:

5

Example 2

Test it Now

Output:

9

Example 3

Test it Now

Output:

-20




Latest Courses