Package org.springframework.web.context.request.async

Examples of org.springframework.web.context.request.async.WebAsyncTask


public class WebAsyncTaskController {

    @RequestMapping("/webAsyncTask1")
    public WebAsyncTask<String> webAsyncTask1(final Model model) {
        long timeout = 10L * 1000; //自定义超时时间 10秒
        WebAsyncTask webAsyncTask = new WebAsyncTask(timeout, new Callable() {
            @Override
            public String call() throws Exception {
                Thread.sleep(2L * 1000);
                model.addAttribute("msg", "hello web async task");
                String viewName = "msg";
View Full Code Here


    }

    @RequestMapping("/webAsyncTask2")
    public WebAsyncTask<String> webAsyncTask2(final Model model) {
        long timeout = 10L * 1000; //自定义超时时间 1秒
        WebAsyncTask webAsyncTask = new WebAsyncTask(timeout, new Callable() {
            @Override
            public String call() throws Exception {
                Thread.sleep(2L * 1000);
                throw new RuntimeException("出错了");
            }
View Full Code Here

    @RequestMapping("/listener3")
    @ResponseBody
    public WebAsyncTask<String> listener3() {
        long timeout = 10L * 1000; //自定义超时时间 10秒
        final WebAsyncTask webAsyncTask = new WebAsyncTask(timeout, new Callable() {
            @Override
            public String call() throws Exception {
                Thread.sleep(2L * 1000);
                return "success";
            }
        });

        webAsyncTask.onTimeout(new Callable() {
            @Override
            public Object call() throws Exception {
                System.out.println("====异步任务超时了");
                return "error";
            }
        });

        webAsyncTask.onCompletion(new Runnable() {
            @Override
            public void run() {
                System.out.println("===异步任务完成了");
            }
        });
View Full Code Here

    @RequestMapping("/listener4")
    @ResponseBody
    public WebAsyncTask<String> listener4() {
        long timeout = 10L * 1000; //自定义超时时间 10秒
        final WebAsyncTask webAsyncTask = new WebAsyncTask(timeout, new Callable() {
            @Override
            public String call() throws Exception {
                Thread.sleep(20L * 1000);
                return "success";
            }
        });

        webAsyncTask.onTimeout(new Callable() {
            @Override
            public Object call() throws Exception {
                System.out.println("====异步任务超时了");
                return "error";
            }
        });

        webAsyncTask.onCompletion(new Runnable() {
            @Override
            public void run() {
                System.out.println("===异步任务完成了");
            }
        });
View Full Code Here

TOP

Related Classes of org.springframework.web.context.request.async.WebAsyncTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.