public boolean accept(long now) {
        long currTokens;
        if (now > nextUpdate) {
            currTokens = tokens.get();
            if (tokens.compareAndSet(currTokens, maxTokens)) {
                nextUpdate = System.currentTimeMillis() / 1000 * 1000 + intervalMillis;
            }
        }

        do {
            currTokens = tokens.get();
        } while (currTokens > 0 && !tokens.compareAndSet(currTokens, currTokens - 1));

        return currTokens > 0;
    }
@Test
    public void testAccept() {
        TokenBucket tokenBucket = new TokenBucket(1, TimeUnit.SECONDS.toMillis(10));
        Assert.assertTrue(tokenBucket.accept(System.currentTimeMillis()));
        Assert.assertFalse(tokenBucket.accept(System.currentTimeMillis()));
    }