Is there a framework to limit method invoke rate in java?

243 Views Asked by At

I hava a java method that can not be invoke more than N times in one second, is there a framework or utils can do this work.

When too many invocations, it can hold and balance the invocation request.

1

There are 1 best solutions below

9
On

I am using this in anti-ddos function in my web application, it is easy to do that.

Firstly you need a database to record the invocation information, say method name and time.

then you can use AOP or interceptor in springmvc or some other technical framework.
record what you are invoking and then check if you are eligible to do that.
While checking eligibility, you need to calculate how many invocation have been done in last N minutes, if exceeded, just deny this invocation!

just have a try!