You've already forked FrameTour-BE
2
This commit is contained in:
@ -12,11 +12,14 @@ public class SlidingWindowRateLimiter {
|
||||
|
||||
public SlidingWindowRateLimiter(int maxRequestsPerSecond) {
|
||||
this.semaphore = new Semaphore(maxRequestsPerSecond);
|
||||
// Schedule a task to release all permits every second
|
||||
scheduler.scheduleAtFixedRate(() -> semaphore.release(maxRequestsPerSecond - semaphore.availablePermits()), 1, 1, TimeUnit.SECONDS);
|
||||
scheduler.scheduleAtFixedRate(() -> {
|
||||
if (semaphore.availablePermits() < maxRequestsPerSecond) {
|
||||
semaphore.release(1);
|
||||
}
|
||||
}, 0, (1000 / maxRequestsPerSecond), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void allowRequest() throws InterruptedException {
|
||||
public void aquire() throws InterruptedException {
|
||||
semaphore.acquire();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user