Skip to content

Instantly share code, notes, and snippets.

@stevenschlansker
Created December 4, 2013 23:47
Show Gist options
  • Save stevenschlansker/7797732 to your computer and use it in GitHub Desktop.
Save stevenschlansker/7797732 to your computer and use it in GitHub Desktop.
ForgettingExecutor
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