Java Thread Executor Execute execute(Callable callable)

Here you can find the source of execute(Callable callable)

Description

execute

License

Apache License

Declaration

private static <T> T execute(Callable<T> callable) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class Main {
    private static <T> T execute(Callable<T> callable) throws Exception {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        try {//from  ww w  . j av  a  2 s.  co  m
            Future<T> task = executor.submit(callable);
            return task.get(10, TimeUnit.SECONDS);
        } finally {
            executor.shutdown();
        }
    }
}

Related

  1. exec(Callable callable)
  2. exec(Runnable... commands)
  3. execute(final Runnable task)
  4. execute(int nThreads, List callables)
  5. execute(Runnable command)
  6. execute(Runnable command)