Class TokenBucket


  • public class TokenBucket
    extends Object
    A lock-free implementation of a token bucket. Tokens can be acquired from the bucket as long as there is sufficient capacity in the bucket.
    • Constructor Detail

      • TokenBucket

        public TokenBucket​(int maxCapacity)
        Create a bucket containing the specified number of tokens.
    • Method Detail

      • release

        public void release​(int amountToRelease)
        Release a certain number of tokens back to this bucket. If this number of tokens would exceed the maximum number of tokens configured for the bucket, the bucket is instead set to the maximum value and the additional tokens are discarded.
      • maxCapacity

        public int maxCapacity()
        Retrieve the maximum capacity of the bucket configured when the bucket was created.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object