public class ConcurrentKits extends Object
copy from vipshop VJTools
| 构造器和说明 |
|---|
ConcurrentKits() |
| 限定符和类型 | 方法和说明 |
|---|---|
static CountDownLatch |
countDownLatch(int count)
返回CountDownLatch, 每条线程减1,减到0时正在latch.wait()的进程继续进行
|
static CyclicBarrier |
cyclicBarrier(int count)
返回CyclicBarrier,每条线程减1并等待,减到0时,所有线程继续运行
|
static Semaphore |
fairSemaphore(int permits)
返回公平的信号量,先请求的线程先拿到信号量
|
static LongAdder |
longAdder()
返回没有激烈CAS冲突的LongAdder, 并发的+1将在不同的Counter里进行,只在取值时将多个Counter求和.
|
static Semaphore |
nonFairSemaphore(int permits)
返回默认的非公平信号量,先请求的线程不一定先拿到信号量
|
static com.google.common.util.concurrent.RateLimiter |
rateLimiter(int permitsPerSecond)
返回令牌桶算法的RateLimiter
|
static Sampler |
sampler(double selectPercent)
返回采样器.
|
static TimeIntervalLimiter |
timeIntervalLimiter(long interval,
TimeUnit timeUnit)
返回时间间隔限制器.
|
public static LongAdder longAdder()
为了保持JDK版本兼容性,统一采用移植版
public static CountDownLatch countDownLatch(int count)
public static CyclicBarrier cyclicBarrier(int count)
public static Semaphore nonFairSemaphore(int permits)
public static Semaphore fairSemaphore(int permits)
public static com.google.common.util.concurrent.RateLimiter rateLimiter(int permitsPerSecond)
public static Sampler sampler(double selectPercent)
selectPercent - 采样率,在0-100 之间,可以有小数位public static TimeIntervalLimiter timeIntervalLimiter(long interval, TimeUnit timeUnit)
interval - 间隔时间timeUnit - 间隔时间单位Copyright © 2019. All rights reserved.