-2

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.

lichengwu
  • 4,277
  • 6
  • 29
  • 42

1 Answers1

1

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!

Rugal
  • 2,612
  • 1
  • 15
  • 16
  • Hmmm ... doing a database query to check invocation counts is likely to make the ddos problem worse rather than better. You need a rate limit check that *does not* add significant extra load. Besides, this doesn't answer the question. The OP wants an existing util / framework, not instructions on how to build one. – Stephen C Jan 09 '14 at 02:52
  • @StephenC I will let web server do the defend first, I just record what client do, but in this question, what this poster need is just same with part of mine logic – Rugal Jan 09 '14 at 02:54
  • That doesn't really address my point. What I'm saying is that your strategy is not a good one. Whether it is first line, second line or Nth line defence, it is still going to be expensive. You add an extra database query and update on every request to your server. Do the math ... – Stephen C Jan 09 '14 at 03:00
  • @Rugal this is not a web app, just a mehod invoking by many threads. – lichengwu Jan 09 '14 at 03:03
  • so you do not want to record any information about the action, but still want to have this defense? – Rugal Jan 09 '14 at 03:04
  • @StephenC Yes, i know how to do this, but i just want a framework. – lichengwu Jan 09 '14 at 03:04
  • @lichengwu know it is not web application, I just provide you with an idea, you need to address it to adapt to your situation. do not `copy` my solution as every solution has its best suitable situation. – Rugal Jan 09 '14 at 03:05
  • @lichengwu you could use file to record it. But you have mentioned, this is an multi-threads application, you need to pay for cope with `synchronization` between different threads, compared with coding a better file writer by yourself, I would rather to use database. – Rugal Jan 09 '14 at 03:08
  • @lichengwu - **I know** that's what you want. If you were paying attention, you'd have noticed that **I told Rugal** that's what you want. Unfortunately, I don't think there is one. – Stephen C Jan 09 '14 at 06:43