Home  >  Q&A  >  body text

并发 - java如果打回相差几毫秒的请求

1.有一个用户在10毫秒内提交了两个请求.前端已经上了应用市场,所以改不了,只能从java下手.
请问怎么设计能将第二个请求直接打回?并且需要考虑并发情况

补充:如果需要对所有的接口都进行这种过滤,请问需要如何设计?

伊谢尔伦伊谢尔伦2742 days ago529

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:57:18

    Write an interceptor and filter it. For filtering two consecutive times separated by more than 10ms

    reply
    0
  • PHPz

    PHPz2017-04-18 10:57:18

    There is a concept in PHP's laravel framework, which is middleware. You can filter all requests with the specified middleware first.

    But it is estimated that in your current situation, you will need to use an in-memory database. Encode the content of the request and insert it into the library (plus the request time field). When responding to the request, first check whether there is a request with the same encoding. If there is no response to the request, if so, compare the time difference before processing.

    Users who request too frequently can be added to the blacklist.

    Of course, a necessary condition for this is that the user can be identified in the requested content, otherwise it will be difficult.

    reply
    0
  • Cancelreply