简体   繁体   English

如何通过Spring MVC将工作线程的响应发布到客户端?

[英]How to post response from worker thread to client via Spring MVC?

I am using spring tool suite 3.3.0. 我正在使用Spring Tool Suite 3.3.0。

I have a request mapping in that I receive from client and start processing and call a different thread for my purpose. 我有一个请求映射,我从客户端收到并开始处理,并为此目的调用了另一个线程。

Is it possible to send response from worker thread? 是否可以从工作线程发送响应?

Code: @RequestMapping(value = "/rcv", method = RequestMethod.POST) 代码:@RequestMapping(值=“ / rcv”,方法= RequestMethod.POST)

public @ResponseBody String home() { //receving from client public @ResponseBody String home(){//从客户端接收

 Thread th = new Thread();
 // my thread process

} }

No. It should work another way. 否。它应该以另一种方式工作。

On first cll you start the thread nd store it somewhere eg in session. 首先,您启动线程nd并将其存储在某个位置,例如在会话中。 Then from client you call it from time to time eg by AJAX call each second you ask whether the thread's job is done. 然后,您不时从客户端调用它,例如通过AJAX每秒调用一次,您询问线程的工作是否完成。 BTW it could also show the progress. 顺便说一句,它也可以显示进度。

When thread has done the job the result is stored again in session and on next AJAX call the result is returned to client 线程完成工作后,结果将再次存储在会话中,并且在下一次AJAX调用时,结果将返回给客户端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM