Runnable
Runnable is the standard way to describe a piece of work that takes no input and returns no result. You hand one to a thread or an executor, and it decides where and when to run it.
Detailed Explanation
A thread needs something to do. Runnable is that something. The whole interface is one method: void run(). No parameters, no return value, no checked exceptions.
The point of the interface is separation. Your code describes what should happen. Something else decides who runs it and when. The same Runnable can go to a raw Thread, to a pool of twenty threads, to a scheduler that runs it every minute, or to the Swing event thread. None of that is visible to the task, which is why task code stays testable: you can call run() directly in a unit test with no threads involved at all.
Before Java 8 you wrote these as anonymous inner classes, five lines of ceremony around one line of work. Runnable is now annotated @FunctionalInterface, so a lambda or a method reference is enough. pool.execute(() -> sendEmail(user)) and pool.execute(this::sendEmail) both work, and both produce an object implementing Runnable.
The missing return value is the defining limitation. If your task computes something — a currency conversion, a row count, a parsed file — Runnable gives you nowhere to put it. The old workaround was a mutable field on the task object, read after join(), which needs its own synchronisation and is easy to read too early. Callable exists precisely to fix this, and it also allows checked exceptions, which run() does not.
That second restriction bites constantly. Almost every interesting operation in Java throws a checked exception: file reads throw IOException, Thread.sleep throws InterruptedException. Inside run() you must catch them there and either handle them or wrap them in a RuntimeException.
How failure is reported depends on how you submitted the task, and the difference surprises people. With Executor.execute(Runnable), an exception that escapes run() reaches the thread's uncaught exception handler and is normally printed. With ExecutorService.submit(Runnable), it is captured inside the returned Future instead. If you never call get() on that Future, the exception is never reported and the task looks like it succeeded.
Runnable carries no memory-model magic of its own. The happens-before edge comes from whatever runs it: Thread.start(), or the executor's guarantee that submitting a task happens-before the task executes. Any state the task shares with other tasks still needs a lock, a volatile field or an atomic class.
Reach for Runnable for fire-and-forget work: log shipping, cache invalidation, sending a notification, cleanup on shutdown. Reach for Callable the moment you need an answer back or want checked exceptions to flow naturally. The cost of Runnable is not performance — a lambda is a cheap object — it is that silent failure is one careless submit() away.
Code Examples
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ReportJob implements Runnable {
private final String customer;
ReportJob(String customer) {
this.customer = customer;
}
@Override
public void run() { // no arguments, no return value, no checked exceptions
System.out.println("building report for " + customer
+ " on " + Thread.currentThread());
}
public static void main(String[] args) {
// Java 21: one virtual thread per task. ExecutorService is AutoCloseable
// since Java 19, so try-with-resources shuts it down for us.
try (ExecutorService pool = Executors.newVirtualThreadPerTaskExecutor()) {
pool.execute(new ReportJob("acme")); // an implementing class
pool.execute(() -> System.out.println("building report for globex")); // a lambda
} // close() waits for the submitted tasks to finish
}
}import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class RunnableFailureModes {
public static void main(String[] args) throws InterruptedException {
Runnable failing = () -> {
throw new IllegalStateException("boom");
};
ExecutorService pool = Executors.newFixedThreadPool(1);
try {
// execute(): the exception escapes to the thread's uncaught handler,
// which prints a stack trace to standard error.
pool.execute(failing);
// submit(): the exception is stored in the Future instead. Nothing
// is printed. Drop the Future and the failure disappears silently.
Future<?> future = pool.submit(failing);
future.get();
} catch (ExecutionException e) {
// get() wraps the original exception exactly once.
System.out.println("caught: " + e.getCause().getMessage()); // boom
} finally {
pool.shutdown();
}
}
}Common Gotchas
`run()` cannot throw checked exceptions
the signature forbids it, so `IOException` and `InterruptedException` must be handled inside the task or wrapped in a `RuntimeException`. If that feels wrong, you wanted `Callable`.
`submit()` hides failures that `execute()` reports
an exception from a `Runnable` passed to `submit()` sits in the `Future` forever unless something calls `get()`. Prefer `execute()` for fire-and-forget work, or always consume the `Future`.
`Runnable` has nothing to do with threads
it is only a task description. Passing one to `new Thread(...)` starts a thread; passing one to `pool.execute(...)` may reuse an existing thread; calling `run()` yourself uses the current thread.