英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论