Example usage for java.util.concurrent Callable Callable

List of usage examples for java.util.concurrent Callable Callable

Introduction

In this page you can find the example usage for java.util.concurrent Callable Callable.

Prototype

Callable

Source Link

Usage

From source file:com.sishuok.chapter3.web.interceptor.MyCallableController.java

@RequestMapping("/myCallable1")
@ResponseBody//from  ww  w .j a  va2  s  .  c o m
public Callable<String> callable1() {
    return new Callable<String>() {
        @Override
        public String call() throws Exception {
            System.out.println("====Callable call");
            return "success";
        }
    };
}

From source file:com.sishuok.chapter3.web.controller.ExceptionController.java

@RequestMapping("/exception")
public Callable<String> exception() {
    return new Callable<String>() {
        @Override//from  w  w  w. j  av  a 2s. co m
        public String call() throws Exception {
            Thread.sleep(2L * 1000);
            throw new RuntimeException("");
        }
    };
}

From source file:com.sishuok.web.controller.pipe.PipeController.java

@RequestMapping("/pipe")
public Callable<String> pipe() throws IOException, InterruptedException {
    return new Callable<String>() {
        @Override//w  w w  .ja  v a2s.c  om
        public String call() throws Exception {
            return "pipe/index";
        }
    };

}

From source file:gov.nih.nci.integration.caaers.invoker.CaAERSServiceInvocationStrategyFactory.java

private static synchronized void init(final String[] caaersLibLocation, final String... caaersConfig) {
    final ExecutorCompletionService<Boolean> ecs = new ExecutorCompletionService<Boolean>(
            Executors.newSingleThreadExecutor());

    ecs.submit(new Callable<Boolean>() {

        @Override/*from   w  ww . ja v  a2 s.co  m*/
        public Boolean call() throws MalformedURLException, BeansException {
            final CustomClasspathXmlApplicationContext ctx = new CustomClasspathXmlApplicationContext(
                    caaersLibLocation, caaersConfig);
            caaersRegistrationServiceInvocationStrategy = (ServiceInvocationStrategy) ctx
                    .getBean("caAersRegistrationServiceInvocationStrategy");
            caaersUpdateRegistrationServiceInvocationStrategy = (ServiceInvocationStrategy) ctx
                    .getBean("caAersUpdateRegistrationServiceInvocationStrategy");
            caaersAdverseEventServiceInvocationStrategy = (ServiceInvocationStrategy) ctx
                    .getBean("caAersAdverseEventServiceInvocationStrategy");
            return Boolean.TRUE;
        }
    });

    try {
        initStatus = ecs.take().get();
        // CHECKSTYLE:OFF
    } catch (Exception e) { // NOPMD
        LOG.error("CaAERSServiceInvocationStrategyFactory.Exception inside init(). ", e);
        initStatus = Boolean.FALSE;
    }
}

From source file:org.zenoss.zep.dao.impl.DaoUtilsTest.java

@Test
public void testDeadlockRetry() throws Exception {
    final AtomicInteger i = new AtomicInteger();
    final int returnVal = new Random().nextInt();
    int result = DaoUtils.deadlockRetry(new Callable<Integer>() {
        @Override//  w w  w .ja v a2 s .  c o  m
        public Integer call() throws Exception {
            if (i.incrementAndGet() < 5) {
                throw new DeadlockLoserDataAccessException("My fake exception", null);
            }
            return returnVal;
        }
    });
    assertEquals(i.get(), 5);
    assertEquals(result, returnVal);
}

From source file:org.springside.samples.quickservice.functional.TaskRestServiceTest.java

@BeforeClass
public static void start() throws Exception {
    Future<ConfigurableApplicationContext> future = Executors.newSingleThreadExecutor()
            .submit(new Callable<ConfigurableApplicationContext>() {
                @Override/*from w  w  w  .ja va  2s .  c  om*/
                public ConfigurableApplicationContext call() throws Exception {
                    return SpringApplication.run(QuickServiceApplication.class);
                }
            });
    context = future.get(60, TimeUnit.SECONDS);
}

From source file:com.sishuok.chapter3.web.controller.WebAsyncTaskController.java

@RequestMapping("/webAsyncTask1")
public WebAsyncTask<String> webAsyncTask1(final Model model) {
    long timeout = 10L * 1000; // 10
    WebAsyncTask webAsyncTask = new WebAsyncTask(timeout, new Callable() {
        @Override/*from   ww  w .  j a  v  a 2s.  c  o  m*/
        public String call() throws Exception {
            Thread.sleep(2L * 1000);
            model.addAttribute("msg", "hello web async task");
            String viewName = "msg";
            return viewName;
        }
    });
    return webAsyncTask;
}

From source file:com.parse.ParseCurrentConfigController.java

public Task<Void> setCurrentConfigAsync(final ParseConfig config) {
    return Task.call(new Callable<Void>() {
        @Override//from w ww .  j av a  2s  .c o  m
        public Void call() throws Exception {
            synchronized (currentConfigMutex) {
                currentConfig = config;
                saveToDisk(config);
            }
            return null;
        }
    }, ParseExecutors.io());
}

From source file:org.fcrepo.camel.indexing.solr.integration.TestUtils.java

public static Callable<Integer> solrCount(final String url) {
    final ObjectMapper mapper = new ObjectMapper();

    return new Callable<Integer>() {
        public Integer call() throws Exception {
            return mapper.readTree(httpGet(url)).get("response").get("numFound").asInt();
        }/*from w  w  w .j  av a  2s .com*/
    };
}

From source file:com.sishuok.chapter3.web.controller.CallableController.java

@RequestMapping("/callable1")
public Callable<String> callable1(final Model model) {
    return new Callable<String>() {
        @Override/*from w w w  .ja  v  a  2  s .c  om*/
        public String call() throws Exception {
            Thread.sleep(2L * 1000); //?
            String viewName = "msg";
            model.addAttribute("msg", "hello callable");
            return viewName; //??
        }
    };
}