我正在使用Guava 18.0 RateLimiter:
public static void simpleTst() throws Exception{
RateLimiter lt = RateLimiter.create(2);
_log.info("Acquired one " + lt.tryAcquire());
_log.info("Acquired two " + lt.tryAcquire());
}
Run Code Online (Sandbox Code Playgroud)
输出是:
: 08 16:22:10 PST.INFO1*RateLimiterTst~simpleTst@37: Acquired one true
: 08 16:22:10 PST.INFO1*RateLimiterTst~simpleTst@38: Acquired two false
Run Code Online (Sandbox Code Playgroud)
指定许可证数量12:
public static void simpleTst() throws Exception{
RateLimiter lt = RateLimiter.create(2);
_log.info("Acquired one " + lt.tryAcquire(12));
_log.info("Acquired two " + lt.tryAcquire());
}
Run Code Online (Sandbox Code Playgroud)
输出是:
: 08 16:22:36 PST.INFO1*RateLimiterTst~simpleTst@37: Acquired one true
: 08 16:22:36 PST.INFO1*RateLimiterTst~simpleTst@38: Acquired two false
Run Code Online (Sandbox Code Playgroud)
为什么会这样?