Java / Java Concurrency and Multi Threading in Java 17 and Java 21 Interview questions
What is the Runnable interface used for?
Runnable is a functional interface with a single abstract method, void run(), that takes no arguments and returns no value.
It represents a unit of work that can be executed by a thread without tying that logic to any particular execution mechanism. The same Runnable can be passed to a plain Thread, submitted to an ExecutorService, scheduled with a ScheduledExecutorService, or run on a virtual thread.
Because it's a functional interface, it works naturally with lambda expressions and method references, which is why modern Java code rarely subclasses Thread directly.
Its main limitation is that run() can't return a result or throw a checked exception; when a task needs to produce a value or report a checked failure, Callable<V> is used instead.
More Related questions...