shz.core.reference.JReference Maven / Gradle / Ivy
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;
}
}