Reputation: 1
I created an Executor with fixed thread pool size of 50 when I had to process 1500 tasks in total using guava rate limiter(5 permits/second). But I still got 429 for some tasks. Tasks mean calling 3rd Party API.
How can I make strictly 5 calls per second to third party API?
Upvotes: 0
Views: 420
Reputation: 25
I had similar problemas, I would use Bucket4J
Create
Bandwidth limit = Bandwidth.classic(permitsPerSecond,
Refill.intervally(permitsPerSecond, Duration.ofSeconds(1L)));
Bucket bucket = Bucket.builder().
addLimit(limit).
build();
then
bucket.tryConsume()
or
bucker.asBlocking().consume()
Hope it helps
Upvotes: 0