© Ralph Lecessi 2019
Ralph LecessiFunctional Interfaces in Javahttps://doi.org/10.1007/978-1-4842-4278-0_13

13. Use in Multithreaded Programs

Ralph Lecessi1 
(1)
Kendall Park, NJ, USA
 

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 ...

Get Functional Interfaces in Java: Fundamentals and Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.