RateLimiter - discovering Google Guava | NoBlogDefFound
RateLimiter
class was recently added to Guava libraries (since 13.0) and it is already among my favourite tools. Have a look what the JavaDoc says: [...] rate limiter distributes permits at a configurable rate. Each acquire()
blocks if necessary until a permit is available [...] Rate limiters are often used to restrict the rate at which some physical or logical resource is accessed
Basically this small utility class can be used e.g. to limit the number of requests per second your API wishes to handle or to throttle your own client code, avoiding denial of service of someone else's API if we are hitting it too often.Let's start from a simple example. Say we have a long running process that needs to broadcast its progress to supplied listener:
Read full article from RateLimiter - discovering Google Guava | NoBlogDefFound
No comments:
Post a Comment