首页 > 其他分享 >Ali开源软件Sentinel的思考 Issue #59:关于线程限流问题的讨论

Ali开源软件Sentinel的思考 Issue #59:关于线程限流问题的讨论

时间:2023-02-02 22:00:40浏览次数:41  
标签:threadMax 59 Ali int res 限流 atomic boolean public


interface Limiter {
boolean canPass();
void exit();
}

class FlowLimiter implements Limiter {
private AtomicInteger atomic;
private int threadMax;//通过线程的最大数量

public FlowLimiter(int threadMax){
this.threadMax = Math.abs(threadMax);
this.atomic = new AtomicInteger();
}

@Override
public boolean canPass(){
boolean res = false;

int num = atomic.getAndIncrement();
if(num <= threadMax - 1){
res = true;
}

return res;
}

@Override
public void exit() {
atomic.getAndDecrement();
}

}


标签:threadMax,59,Ali,int,res,限流,atomic,boolean,public
From: https://blog.51cto.com/u_9208248/6033993

相关文章