春季REST服务 – 无需超时的异步请求

huangapple go评论71阅读模式
英文:

Spring REST Service - Asynchronous Requests without Timeout

问题

<br>
我通过调用@Async方法并将CompletableFuture作为响应返回到我的@RestController中,创建了一个异步的Spring REST服务。有没有办法禁用这些异步请求的超时?因为我调用的@Async方法始终需要不同的时间,根据服务的当前工作负载和我在请求中传递的参数,可能需要1到15分钟不等。目前,我将异步请求的超时时间设置为30分钟,只是为了确保不会遇到超时问题。有没有办法取消超时设置?

英文:

<br>
I created an asynchronous Spring REST service by calling an @Async method and returning a CompletableFuture as the response in my @RestController.<br>
Is there any way to disable the timeout for these asynchronous requests? Because the @Async method I am calling always takes a different amount of time, from 1 to 15 minutes depending on the current workload of the service and the parameters I passed in the request.<br><br>

Right now I set the timeout for asynchronous requests to 30 minutes just to be sure not to run into a timeout. Is there any way of disabling the timeout?

答案1

得分: 1

你可以使用 spring.mvc.async.request-timeout 来设置超时时间。不确定是否有方法可以将其禁用,也许将其设置为0可能会起作用。然而,即使超时时间很长,你也应该考虑保留一个超时时间,以免在某种情况下阻塞应用,如果请求可能永远不会完成的话。

英文:

You can use spring.mvc.async.request-timeout to set the timeout. Not sure if there is a way to disable it maybe 0 can work. However even if your timeout is very long, you should consider to keep one to avoid blocking your application if the ask may never complete.

huangapple
  • 本文由 发表于 2020年9月18日 04:11:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63945568.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定