防止客户端重复发送请求 [英] Prevent client repeatedly sending requests

查看:140
本文介绍了防止客户端重复发送请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @RequestMapping(value = {/doSomething.do}我有一个弹簧控制器和请求映射方法。 )
public ModelAndView emailToNonBelievers(){
.....
//做一些需要很多时间的事情

//发送响应..
返回modelAndView;


$ / code>

这个方法需要很长时间,大概一个小时。这是用于管理员,而不是用户,管理员不需要等一个小时,只需开火并忘记,没关系,这不是一个批处理工作)



但我发现客户端以3分钟的间隔重复发送请求(观察6次,我停止了Spring服务)。

我猜是因为客户端没有收到服务器的回应。



如果我的猜测是正确的,服务器应该回应一下你的请求被接受,只是闭嘴,等待!! 。



但是如何在作业完成之前发送响应(200 OK)?

解决方案

在这种情况下,建议使用异步任务处理。

Spring通过 @Async 注释为其提供开箱即用的支持。

请参阅我的回答,以获取类似查询的详细设置和 here for docs。


I have a spring controller and request mapped method.

@RequestMapping(value = { "/doSomething.do" })
public ModelAndView emailToNonBelievers(){
    .....
    // do something which takes lot of time 

    // send response..
    return modelAndView;

}

This method takes very long time, about an hour.(It is for Admin, not users. And Admin doesn't need to wait an hour. Just fire and forget, that's ok. And this is not a batch job)

But I found that client send requests repeatedly with 3 minutes interval(observed 6 times and I stopeed Spring service).

I guess because client didn't get any response from server.

If my guess is right, server should response sort of "Your request is accepted, just shut up and wait!!" .

But how to send response(200 ok) before jobs finished in Spring?

Or am I missing something?

解决方案

In this situation it would be recommended to use asynchronous task processing.

Spring comes with out-of-box support for it via @Async annotation.

Consult my answer for detailed setup for similar query and here for docs.

这篇关于防止客户端重复发送请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆