Fire and Forget - Runnable Tasks
suggest changeExecutors accept a java.lang.Runnable whose work may be long-running. execute does not promise a different thread: some implementations run the task on the caller.
Usage would be:
Executor exec = anExecutor;
exec.execute(new Runnable() {
@Override public void run() {
//offloaded work, no need to get result back
}
});
execute(Runnable) does not return a computed value. It can throw RejectedExecutionException. An exception thrown by run goes to the executor's uncaught-exception handler.
With Java 8, one can utilize lambdas to shorten the code example.
Executor exec = anExecutor;
exec.execute(() -> {
//offloaded work, no need to get result back
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents