All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shz.core.reference.JReference Maven / Gradle / Ivy

There is a newer version: 2024.0.2
Show newest version
package shz.core.reference;

public final class JReference {
    public volatile long value;

    public JReference() {
    }

    public JReference(long value) {
        this.value = value;
    }

    public long get() {
        return value;
    }

    public void set(long value) {
        this.value = value;
    }

    public long getAndSet(long newValue) {
        long temp = value;
        value = newValue;
        return temp;
    }

    //以下方法多线程内禁止使用
    public long getAndIncrement() {
        long temp = value;
        ++value;
        return temp;
    }

    public long getAndDecrement() {
        long temp = value;
        --value;
        return temp;
    }

    public long getAndAdd(long delta) {
        long temp = value;
        value += delta;
        return temp;
    }

    public long incrementAndGet() {
        return ++value;
    }

    public long decrementAndGet() {
        return --value;
    }

    public long addAndGet(long delta) {
        return value += delta;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy