Java AtomicLong max(AtomicLong x, long y)

Here you can find the source of max(AtomicLong x, long y)

Description

max

License

Open Source License

Declaration

public static boolean max(AtomicLong x, long y) 

Method Source Code


//package com.java2s;
/*-------------------------------------------------------------------------------------------------
 _______ __   _ _______ _______ ______  ______
 |_____| | \  |    |    |______ |     \ |_____]
 |     | |  \_|    |    ______| |_____/ |_____]
    /*www. j  av a  2s .  c o  m*/
 Copyright (c) 2016, antsdb.com and/or its affiliates. All rights reserved. *-xguo0<@
    
 This program is free software: you can redistribute it and/or modify it under the terms of the
 GNU Affero General Public License, version 3, as published by the Free Software Foundation.
    
 You should have received a copy of the GNU Affero General Public License along with this program.
 If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>
-------------------------------------------------------------------------------------------------*/

import java.util.concurrent.atomic.AtomicLong;

public class Main {
    public static boolean max(AtomicLong x, long y) {
        for (;;) {
            long value = x.get();
            if (y > value) {
                if (!x.compareAndSet(value, y)) {
                    continue;
                }
                return true;
            } else {
                return false;
            }
        }
    }
}

Related

  1. getUniqueURIString()
  2. greaterAndSet(long value, AtomicLong atomicValue)
  3. isAtomicLong(final N number)
  4. joinThreads()
  5. lock()
  6. nanoTime()
  7. printProgress(final AtomicLong value)
  8. randomSeed()
  9. removeCustomTime()