public class TokenBucket extends Bucket
BUCKET_HASH_WHEEL_TIMER, hashWheelTask
Constructor and Description |
---|
TokenBucket(int tokenSize,
int interval)
令牌桶构造函数
|
TokenBucket(int tokenSize,
int interval,
int releaseTime)
令牌桶构造函数
|
Modifier and Type | Method and Description |
---|---|
boolean |
acquire()
获取令牌, 立即返回
|
void |
acquire(int timeout)
获取令牌, 带有时间等待
|
int |
getReleaseTime() |
void |
init(int tokenSize,
int interval,
int releaseTime)
令牌桶构造函数
|
void |
setReleaseTime(int releaseTime) |
getHashWheelTask, release, setHashWheelTask
public TokenBucket(int tokenSize, int interval, int releaseTime)
tokenSize
- 令牌桶默认大小, 每个时间周期新增的量interval
- 令牌桶的新增周期, 每次触发新增一个令牌到令牌桶, 单位: 毫秒releaseTime
- 令牌桶失效并自动移除的时间public TokenBucket(int tokenSize, int interval)
tokenSize
- 令牌桶默认大小interval
- 令牌桶的新增周期, 每次触发新增一个令牌到令牌桶, 单位: 毫秒public void init(int tokenSize, int interval, int releaseTime)
tokenSize
- 令牌桶默认大小interval
- 令牌桶的新增周期, 每次触发新增一个令牌到令牌桶, 单位: 毫秒releaseTime
- 令牌存活自动释放时间public int getReleaseTime()
public void setReleaseTime(int releaseTime)
public boolean acquire()
public void acquire(int timeout) throws TimeoutException
acquire
in class Bucket
timeout
- 等待时间TimeoutException
- 超时异常Copyright © 2020 Voovan. All rights reserved.