CKTIS / Java
Runnable — a task without a return value
Runnable describes an operation with no parameters and no return value. Its run() method defines the task's action; calling that method alone does not start a new thread.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
@FunctionalInterface
public interface Runnable {
void run();
}Runnable in java.lang is a functional interface describing an operation without a return value. You can implement it with a class or express it as a lambda expression or method reference.
Runnable.run has the signature void run(): it takes no arguments, returns no result, and declares no checked exceptions. A class implementation must be public; checked exceptions arising in its code must be handled unless they are caught inside the methods being called.
A task is not a thread. Calling task.run() directly executes the operation in the current thread, like an ordinary method call. To execute it in a new thread, you can pass the task to new Thread(task) and call start() on the resulting object. Constructing the Thread object alone does not start execution.
The example deliberately calls task.run() directly. This demonstrates execution order without concurrency: Before, Task completed, After.
Examples
public class Main {
public static void main(String[] args) {
Runnable task = () -> System.out.println("Task completed");
System.out.println("Before");
task.run();
System.out.println("After");
}
}Result
Before Task completed After
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.