Java AtomicLong weakCompareAndSet() Method

The weakCompareAndSet() method of java AtomicLong class atomically sets the value to the given updated value if the current value is equal to the expected value. May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to compareAndSet.

Syntax

Parameters

expectedValue - the expected value

newValue - the new value

Returns

true if successful

Example 1

Test it Now

Output:

111

Example 2

Test it Now

Output:

0

Example 3

Test it Now

Output:

-45

Example 4

Test it Now

Output:

-10




Latest Courses