@RequestMapping(value = "/endpoint",method = RequestMethod.POST)
public ResponseEntity
在Java spring controller中,我有一个端点.调用此端点时,我希望它直接返回,而不是等待somefunction()完成.任何人都可以教我如何处理这个问题?
最佳答案
如果您使用的是Java 8,则可以使用新的Executor类:
@RequestMapping(value = "/endpoint",method = RequestMethod.POST)
public ResponseEntity
这将:
>安排somefunction()在延迟10秒后运行.
>返回HTTP 202已接受(当您的POST端点实际上没有在现场创建任何内容时,应该返回此值).
> 10秒后运行somefunction().