Java AtomicLong compareAndSetIfGreater(final AtomicLong dest, final long tryValue)

Here you can find the source of compareAndSetIfGreater(final AtomicLong dest, final long tryValue)

Description

If dest only ever monotonically increases, this function is guaranteed to return with dest having a value of at least tryValue and preserves monotonicity.

License

Open Source License

Parameter

Parameter Description
dest a parameter
tryValue a parameter

Declaration

public static final boolean compareAndSetIfGreater(final AtomicLong dest, final long tryValue) 

Method Source Code

//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;
    }
}

Related

  1. add(AtomicLong requested, long n)
  2. add(AtomicLongFieldUpdater updater, T instance, long n)
  3. addAndGet(AtomicLong current, long toAdd)
  4. addstat(Map stat, String key)
  5. average(Stream stream)
  6. createAtomicId()
  7. createId(final Long baseId)
  8. createObjectID()
  9. createUniqueFileName(String out)