Here you can find the source of execute(Callable
private static <T> T execute(Callable<T> callable) throws Exception
//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(); } } }