MappedFile关闭问题

appedFile destroy将调用ReferenceResource关闭方法, 对refCount有些困惑?

this.refCount.set(-1000 this.getRefCount())

应替换为

this.refCount.set(-1000+this.getRefCount());

我认为目的是每次递减1000直到0

public abstract class ReferenceResource {

protected final AtomicLong refCount = new AtomicLong(1);
protected volatile boolean available = true;
protected volatile boolean cleanupOver = false;
private volatile long firstShutdownTimestamp = 0;

public synchronized boolean hold() {
    if (this.isAvailable()) {
        if (this.refCount.getAndIncrement() > 0) {
            return true;
        } else {
            this.refCount.getAndDecrement();
        }
    }

    return false;
}

public boolean isAvailable() {
    return this.available;
}

public void shutdown(final long intervalForcibly) {
    if (this.available) {
        this.available = false;
        this.firstShutdownTimestamp = System.currentTimeMillis();
        this.release();
    } else if (this.getRefCount() > 0) {
        if ((System.currentTimeMillis() - this.firstShutdownTimestamp) >= intervalForcibly) {
            // some confusion here
            this.refCount.set(-1000 - this.getRefCount());
            this.release();
        }
    }
}

原提问者GitHub用户lebron374

展开
收起
芬奇福贵 2023-05-26 11:46:04 76 分享 版权
1 条回答
写回答
取消 提交回答
  • 我认为这里(-1000this.getRefCount())可能意味着:它只想将refCount设置为负值,表示关闭。(-1000)只是一个“足够负”的数字,可以保证结果(-1000this.getRefCount())始终为负。

    原回答者GitHub用户imaffe

    2023-05-26 17:35:19
    赞同 展开评论
问答地址:

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

还有其他疑问?
咨询AI助理