[英]Is there analog of AsyncContext in spring mvc?(how to write http response in another thread)
I have google about spring support of servlet 3.0/3.1 specification and most of information I have found at this article: Understanding Callable and Spring DeferredResult 我有关于servlet 3.0 / 3.1规范的spring支持以及我在本文中找到的大部分信息的google: 了解Callable和Spring DeferredResult
Here author say that you can return Callable
or DefferedResult
from controller and say it is servlet 3.0/3.1 maintain in spring. 这里作者说你可以从控制器返回
Callable
或DefferedResult
,并说它是在春天的servlet 3.0 / 3.1维护。
But I don't understand how to apply it in my situation: 但我不明白如何在我的情况下应用它:
I have external system and I get result from this system asynchrounously. 我有外部系统,我从异步系统得到了这个系统的结果。
In controller I write something like this: 在控制器中我写这样的东西:
externalSystenm.send(requestId, message);
and I have another thread where I get result: 我有另一个线程,我得到结果:
Message m = externalSystem.get();
m.getRequestId();// According this id I can map message to request
I know that in servlet API I allow to save asyncContext in map and then found it. 我知道在servlet API中我允许在地图中保存asyncContext然后找到它。
How can I acheve it in spring ? 我怎么能在春天去疼呢?
I have found following article: Spring MVC 3.2 Preview: Introducing Servlet 3, Async Support 我找到了以下文章: Spring MVC 3.2预览:介绍Servlet 3,异步支持
example: 例:
@RequestMapping("/quotes")
@ResponseBody
public DeferredResult<String> quotes() {
DeferredResult<String> deferredResult = new DeferredResult<String>();
// Add deferredResult to a Queue or a Map...
return deferredResult;
}
// In some other thread... <-- important phrase
deferredResult.setResult(data);
// Remove deferredResult from the Queue or Map
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.