Section 13.1: Performing Computations Using Runnable and Callable
Runnable is an interface whose implementations contain computations meant to be performed in a thread separate from the calling thread. It is a functional interface containing functional method run which takes no arguments and returns no value.
@FunctionalInterface
public interface Runnable {
void run();
}
The following example defines an implementation of Runnable
. When its run method is called, “RED” is displayed.
Runnable r = () -> System.out.println("RED");
r.run();
OUTPUT:
RED
A Runnable is usually wrapped ...