How to go about implementing a "fire and forget" behavior with java.util.concurrency? I tried:
ExecutorService executor = Executors.newSingleThreadExecutor();
public void push(Callable<Boolean> task) {
Future<Boolean> future = executor.submit(task);
future.get(timeout, timeoutUnit);
}
but the get()
is blocking until completion. The push()
caller is not interested in the result of the task.
Don't call
get()
.submit()
is enough to start theCallable
in aThread
. You can pass around theFuture
and call itsget()
when you are ready to get the result (if ever).The Javadoc states
So just don't call
get()
.