SpringBoot之Callable处理异步请求

/**
 * @Classname CallableController
 * @Description TODO
 * @Date 2020/11/22 17:33
 * @Created by XinHai.Ma
 */
@RequestMapping("/callable")
@RestController
public class CallableController {

    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public Callable<Map<String, Object>> createData() throws RuntimeException {
        return new Callable<Map<String, Object>>() {
            @Override
            public Map<String, Object> call() throws Exception {
                Map<String, Object> result = new HashMap<>();
                result.put("code", 200);
                result.put("message", "success");
                return result;
            }
        };
    }

}

 

就这么写,处理Callable的线程池就不用配置了

posted @ 2020-11-22 17:50  尘世间迷茫的小书童  阅读(1795)  评论(0编辑  收藏  举报