简体   繁体   English

在spring mvc中是否有AsyncContext的模拟?(如何在另一个线程中写入http响应)

[英]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. 这里作者说你可以从控制器返回CallableDefferedResult ,并说它是在春天的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.

相关问题 使用Spring MVC和JSP进行响应分块:如何将JSP的内容写入响应? - response chunking with Spring MVC & JSP: how to write contents of JSP into response? 如何通过Spring MVC将工作线程的响应发布到客户端? - How to post response from worker thread to client via Spring MVC? 如何在HTTP响应中进行单元测试“缓存控制”-Spring MVC Application - How to unit test “cache control” in http response - spring mvc application 使用AsyncContext的HttpServlet没有响应 - No response from HttpServlet with AsyncContext Spring MVC返回HTTP 406响应 - Spring MVC Returning HTTP 406 Response Spring MVC重定向,HTTP POST响应 - Spring MVC Redirect with Response from HTTP POST Spring MVC testframework因HTTP Response 406而失败 - Spring MVC testframework fails with HTTP Response 406 如何在Spring MVC 2.5应用程序中更改HTTP OPTIONS请求的响应? - How do I change the response for a HTTP OPTIONS request in a Spring MVC 2.5 application? Spring MVC将HTTP POST请求作为HTTP GET转发到另一个控制器 - Spring MVC forwarding HTTP POST request as a HTTP GET to another controller Spring 引导记录 HTTP 请求和响应并将日志写入 SQL 数据库 - Spring Boot Logging HTTP request and response and write logs to an SQL database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM