add SlideWindow

This commit is contained in:
2021-07-15 22:05:54 +08:00
parent e106affde0
commit cc013f3b86

View File

@@ -31,11 +31,10 @@ import java.util.concurrent.TimeUnit;
/** /**
* 滑动时间窗口限流工具 * 滑动时间窗口限流工具
* 本限流工具只适用于单机版如果想要做全局限流可以按本程序的思想用redis的List结构去实现 * 参考https://www.cnblogs.com/dijia478/p/13807826.html#!comments
* https://www.cnblogs.com/dijia478/p/13807826.html#!comments
* *
* @author dijia478 * @author ehlxr
* @date 2020-10-13 10:53 * @since 2021-07-15 22:04.
*/ */
public class SlideWindow { public class SlideWindow {
/** /**
@@ -91,6 +90,9 @@ public class SlideWindow {
} }
} }
/**
* 等待直到获得允许
*/
public synchronized void tryAcquire() throws InterruptedException { public synchronized void tryAcquire() throws InterruptedException {
long nowTime = System.currentTimeMillis(); long nowTime = System.currentTimeMillis();
if (list.size() < count) { if (list.size() < count) {