BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #34108同步于 2014/8/26
Java机器人发帖

关于REST框架Jersey中ChunkedOutput的使用

jiadi
2014/8/26镜像同步0 回复
@Path("/resource") public class AsyncResource { @GET public ChunkedOutput<String> getChunkedResponse() { final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class); new Thread() { public void run() { try { String chunk = "json string"; output.write(chunk); } catch (IOException e) { // IOException thrown when writing the // chunks of response: should be handled } try { output.close(); } catch (IOException e) { // IOException thrown when writing the // chunks of response: should be handled } } }.start(); // the output will be probably returned even before // a first chunk is written by the new thread return output; } 问题描述:我第一次GET这个资源的时候浏览器能得到chunk里的json串,但只要我刷新页面,即第二次GET时,浏览器就一直处于加载状态,停止加载再次刷新时又能正确response,感觉就像第一次连接没断开,第二次连接因上次还处于连接状态就一直等待一样,等第三次刷新的时候就断开重连。 请了解chunkoutput机制的同学帮忙看看问题可能出在哪个地方,谢谢!
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。