##背景
有一些批处理的东东,后台执行可能超时,如果等最后遇到错误或者有什么结果才返回,往往会超时,而且整个执行过程的细节也都没法看到,是个黑盒,不大方面调试。这里讲一下如果实现类似websocket的效果,就是后端不断往流里头写文本。
##controller
@Controller
@RequestMapping("/echo")
public class EchoController {
@RequestMapping(value = "/reply",method = RequestMethod.GET)
public void writeStream(HttpServletResponse response) throws IOException, InterruptedException {
response.setContentType("text/html;charset=utf-8");
for(int i=0;i<1000;i++){
write(response,"hello");
Thread.sleep(1000*2);
System.out.println("send");
}
response.getWriter().close();
}
private void write(HttpServletResponse response,String content) throws IOException {
response.getWriter().wri