Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the advantage of using a library like Guava RateLimiter over simple Thread.sleep?

Assuming all I want to do is call a service at a particular rate, say 1 per second, what advantages does Guava RateLimiter offer over simple Thread.sleep(1000) ?

like image 445
Jatin Avatar asked Dec 24 '22 17:12

Jatin


1 Answers

The point of RateLimiter is you make it part of the service (or wrap the service) being called, so it can protect itself from being called too frequently. Your Thread#sleep alternative would have to be used by the client of the service, so you're comparing two different things.

Here's a good article on what you can do with RateLimiter.

like image 132
Nathan Hughes Avatar answered Jan 30 '23 18:01

Nathan Hughes