Spring长轮询

MUEDSA,Development

DeferredResult

org.springframework.web.context.request.async.DeferredResult

@GetMapping("/async-deferredresult")
public DeferredResult<ResponseEntity<?>> handleReqDefResult(Model model) {
    LOG.info("Received async-deferredresult request");
    DeferredResult<ResponseEntity<?>> output = new DeferredResult<>();
 
    ForkJoinPool.commonPool().submit(() -> {
        LOG.info("Processing in separate thread");
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
        }
        output.setResult(ResponseEntity.ok("ok"));
    });
 
    LOG.info("servlet thread freed");
    return output;
}

more:

© MUEDSA BLOG.RSS