TokenBucket { public void consume() { consume(1); } TokenBucket(long capacity, long initialTokens, RefillStrategy refillStrategy, SleepStrategy sleepStrategy); long getCapacity(); synchronized long getNumTokens(); long getDurationUntilNextRefill(TimeUnit unit); boolean tryConsume(); synchronized boolean tryConsume(long numTokens); void consume(); void consume(long numTokens); synchronized void refill(long numTokens);  }
@Test public void test() { TokenBucket bucket = new TokenBucket(3, 3, new RefillStrategy(6, Duration.ofSeconds(1)), () -> { }); bucket.consume(); bucket.consume(); bucket.consume(); bucket.consume(); }