Fire and Forget - Runnable Tasks

suggest change

Executors 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
});

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents