Executors accept a java.lang.Runnable
which contains (potentially computationally or otherwise long-running or heavy) code to be run in another Thread.
Usage would be:
Executor exec = anExecutor;
exec.execute(new Runnable() {
@Override public void run() {
//offloaded work, no need to get result back
}
});
Note that with this executor, you have no means to get any computed value back.
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
});