-
-
Save cassc/deea6850c7ff5046b0ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(value="/pushMsg") | |
public void pushMsg(HttpServletRequest request, HttpServletResponse response){ | |
long t0 = System.currentTimeMillis(); | |
log.info("Starting "); | |
Continuation continuation = ContinuationSupport.getContinuation(request); | |
continuation.setTimeout(5000); | |
continuation.suspend(); | |
long t1 = System.currentTimeMillis(); | |
log.info("Suspended "); | |
Integer count=(Integer) continuation.getAttribute("count"); | |
if(count==null){ | |
continuation.setAttribute("count", 0); | |
count=0; | |
}else{ | |
// continuation.resume(); | |
} | |
long t2 = System.currentTimeMillis(); | |
PrintWriter pw =null; | |
try { | |
pw = response.getWriter(); | |
response.setContentType("text/plain"); | |
pw.write("msg: "+count++); | |
// TimeUnit.SECONDS.sleep(5); | |
continuation.setAttribute("count", count); | |
log.info("Sending msg "+(count-1)+", expired? "+continuation.isExpired()); | |
long t3 = System.currentTimeMillis(); | |
if(count>10){ | |
continuation.complete(); | |
log.info("stopping continuation"); | |
} | |
} catch (Exception e) { | |
log.error("",e); | |
if(pw!=null){ | |
pw.write("error"); | |
} | |
continuation.complete(); | |
long t4 = System.currentTimeMillis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment