Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 java 方法can not be invoke more than N times in one second,是否有框架或工具可以完成这项工作。
can not be invoke more than N times in one second
当调用过多时,它可以保持和平衡调用请求。
我在我的 Web 应用程序的反 ddos 功能中使用它,很容易做到这一点。
首先,您需要一个数据库来记录调用信息,例如method name和time。
method name
time
然后你可以使用AOPor interceptorinspringmvc或者其他一些技术框架。 记录您正在调用的内容,然后检查您是否有资格这样做。 在检查资格时,您需要计算在最后N几分钟内执行了多少次调用,如果超过,则拒绝此调用!
AOP
interceptor
springmvc
N
试一试!