Example usage for org.springframework.web.context.request.async WebAsyncTask onCompletion

List of usage examples for org.springframework.web.context.request.async WebAsyncTask onCompletion

Introduction

In this page you can find the example usage for org.springframework.web.context.request.async WebAsyncTask onCompletion.

Prototype

public void onCompletion(Runnable callback) 

Source Link

Document

Register code to invoke when the async request completes.

Usage

From source file:com.sishuok.chapter3.web.listener.ListenerController.java

@RequestMapping("/listener3")
@ResponseBody/*  www . ja va 2 s  .c  o  m*/
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("===?");
        }
    });

    return webAsyncTask;
}

From source file:com.sishuok.chapter3.web.listener.ListenerController.java

@RequestMapping("/listener4")
@ResponseBody//from www.  j  av  a2  s .c o  m
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("===?");
        }
    });

    return webAsyncTask;
}