Created
January 27, 2010 17:40
-
-
Save stacktracer/288035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <V> V callInterruptibly(Callable<V> callable) throws InterruptedException | |
{ | |
ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() | |
{ | |
public Thread newThread(Runnable runnable) | |
{ | |
Thread thread = Executors.defaultThreadFactory().newThread(runnable); | |
thread.setDaemon(true); | |
return thread; | |
} | |
}); | |
Future<V> future = executor.submit(callable); | |
try | |
{ | |
return future.get(); | |
} | |
catch (ExecutionException e) | |
{ | |
throw new RuntimeException(e); | |
} | |
finally | |
{ | |
executor.shutdownNow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment