一、Callable(Runnable)异步处理请求

       SpringBoot异步处理服务请求

 

@GetMapping("/async")
    public ResultVO asyncTest() throws Exception {
        log.info("主线程start");
        Callable<ResultVO> result = new Callable<ResultVO>() {
            @Override
            public ResultVO call() throws Exception {
                log.info("副线程start");
                Thread.sleep(15000);
                log.info("副线程end");
                return ResultVO.ofSuccess(null);
            }
        };

        log.info("主线程end");
        return result.call();
    }

业务逻辑在call()方法中实现。 

SpringBoot异步处理服务请求 

相关文章: