Skip to content

Bucket4J for client-side rate limiting #96

Discussion options

You must be logged in to vote

Hello @aritzbastida

To avoid thread blocking you need to use asAsyncScheduler(instead of asScheduler) and pass your custom implementation of ScheduledExecutorService as a parameter to any method of interface AsyncScheduledBucket. You really need to implement only one method of ScheduledExecutorService:

public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit);

Other methods of ScheduledExecutorService are unused by Bucket4j. Inside the implementation of schedule, you are able to delegate postponed processing to anywhere you want. ScheduledFuture that returned also not used by Bucket4j, so do not spend efforts to provide correctly result.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by vladimir-bukhtoyarov
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #96 on December 21, 2020 15:35.