AtomicLong.getAndSet(long newValue) has the following syntax.
public final long getAndSet(long newValue)
In the following code shows how to use AtomicLong.getAndSet(long newValue) method.
/*from w w w . j a v a 2s . co m*/ import java.util.concurrent.atomic.AtomicLong; public class Main { public static void main(String[] argv) { AtomicLong nextId = new AtomicLong(); System.out.println(nextId.getAndSet(123123L)); System.out.println(nextId.getAndIncrement()); } }
The code above generates the following result.