Here you can find the source of compareAndSetIfGreater(final AtomicLong dest, final long tryValue)
Parameter | Description |
---|---|
dest | a parameter |
tryValue | a parameter |
public static final boolean compareAndSetIfGreater(final AtomicLong dest, final long tryValue)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.atomic.AtomicLong; public class Main { /***//from ww w . j av a 2 s. c o m * If dest only ever monotonically increases, this function is guaranteed to return with * dest having a value of at least tryValue and preserves monotonicity. * @param dest * @param tryValue * @return */ public static final boolean compareAndSetIfGreater(final AtomicLong dest, final long tryValue) { long destValue; do { destValue = dest.get(); if (tryValue <= destValue) { return false; } } while (!dest.compareAndSet(destValue, tryValue)); return true; } }