org.rx.bean.AbstractReferenceCounter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxlib Show documentation
Show all versions of rxlib Show documentation
A set of utilities for Java
package org.rx.bean;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
//Save memory
public abstract class AbstractReferenceCounter {
protected static final AtomicIntegerFieldUpdater updater = AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCounter.class, "refCnt");
protected volatile int refCnt;
public int getRefCnt() {
return updater.get(this);
}
public int incrementRefCnt() {
return updater.incrementAndGet(this);
}
public int decrementRefCnt() {
return updater.decrementAndGet(this);
}
}