Created
December 4, 2013 23:47
-
-
Save stevenschlansker/7797732 to your computer and use it in GitHub Desktop.
ForgettingExecutor
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 class ForgettingExecutor | |
{ | |
private ForgettingExecutor() { } | |
public static <T> Future<T> submit(ExecutorService executor, Callable<T> callable) | |
{ | |
return executor.submit(new ForgettingCallable<>(new AtomicReference<>(callable))); | |
} | |
private static class ForgettingCallable<T> implements Callable<T> | |
{ | |
private final AtomicReference<Callable<T>> callable; | |
public ForgettingCallable(AtomicReference<Callable<T>> callable) | |
{ | |
this.callable = callable; | |
} | |
@Override | |
public T call() throws Exception | |
{ | |
try { | |
return callable.get().call(); | |
} finally { | |
callable.set(null); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment