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

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

Introduction

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

Prototype

public void onTimeout(Callable<V> callback) 

Source Link

Document

Register code to invoke when the async request times out.

Usage

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

@RequestMapping("/listener3")
@ResponseBody/*from w  w  w  .ja v  a2  s.  c om*/
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 ww  w . java  2s  .  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;
}