高并发限流(二)——应用举例

1.对单个接口的总并发数进行限制 1.利用一个AtomicLong变量进行简单粗暴的限流 try { if(atomic.incrementAndGet() > 限流数) { //拒绝请求 } //处理请求 } finally { atomic.decrementAndGet(); } 2.利用SHARED模式的ReentrantLock try {
相关文章
相关标签/搜索