Here you can find the source of run(Callable
public static <T> T run(Callable<T> task, long timeout) throws Exception
//package com.java2s; //License from project: Open Source License import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; public class Main { public static <T> T run(Callable<T> task, long timeout) throws Exception { FutureTask<T> future = new FutureTask<T>(task); new Thread(future).start(); T r = null;//from www.ja v a 2 s. c o m try { r = future.get(timeout, TimeUnit.MILLISECONDS); } finally { try { future.cancel(true); } catch (Exception ex) { } } return r; } }