Here you can find the source of execute(String name, Runnable runnable)
Parameter | Description |
---|---|
runnable | a parameter |
@Deprecated public static Future<?> execute(String name, Runnable runnable)
//package com.java2s; //License from project: Apache License import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class Main { /**/*from ww w . j a va 2 s . c o m*/ * @deprecated Should be using worker threads for everything really * @param runnable * @return */ @Deprecated public static Future<?> execute(String name, Runnable runnable) { final Thread thread = new Thread(runnable, name); Future<?> future = new Future<Void>() { public boolean cancel(boolean mayInterruptIfRunning) { return false; } public boolean isCancelled() { return false; } public boolean isDone() { return !thread.isAlive(); } public Void get() throws InterruptedException, ExecutionException { thread.join(); return null; } public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { thread.join(unit.toMillis(timeout)); if (thread.isAlive()) { throw new TimeoutException("Thread is still alive after timeout"); } return null; } }; thread.start(); return future; } /** * @deprecated Should be using worker threads for everything really * @param runnable * @return */ @Deprecated public static <T> Future<T> execute(Callable<T> callable) { Future<T> future = Executors.newFixedThreadPool(1).submit(callable); return future; } }