Runnable vs Callable in Java: Key Differences with Examples
Runnable and Callable both describe a unit of work that another thread can run. The difference is what comes back: a Runnable returns nothing, while a Callable returns a result and can throw checked exceptions.
This tutorial compares the two side by side, shows the same task written both ways, and explains how to choose between them.
1. Quick Comparison
| Feature | Runnable | Callable<V> |
|---|---|---|
| Package | java.lang | java.util.concurrent |
| Introduced | Java 1.0 | Java 5 |
| Method | void run() | V call() throws Exception |
| Returns a value | No | Yes, of type V |
| Checked exceptions | Must be caught inside | Can be thrown to the caller |
Accepted by Thread | Yes | No (wrap in FutureTask) |
Accepted by ExecutorService | execute() and submit() | submit(), invokeAll(), invokeAny() |
| Functional interface | Yes | Yes |
2. Syntax
// java.lang.Runnable
@FunctionalInterface
public interface Runnable {
void run();
}
// java.util.concurrent.Callable
@FunctionalInterface
public interface Callable<V> {
V call() throws Exception;
}
Both are functional interfaces, so a lambda can implement either one. The compiler picks Callable when the lambda body returns a value and Runnable when it does not.
3. Example: The Same Task Written Both Ways
A warehouse job synchronises stock-keeping units (SKUs). Written as a Runnable it can only report by printing; written as a Callable it hands the count back to the caller.
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class StockSyncComparison {
static final List<String> WAREHOUSE_SKUS = List.of("KB-01", "MS-07", "HD-12", "CB-03");
public static void main(String[] args) throws InterruptedException, ExecutionException {
try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
// Runnable: does the work, returns nothing
Runnable syncAsRunnable = () -> System.out.println("Runnable synced " + WAREHOUSE_SKUS.size() + " SKUs");
Future<?> f1 = executor.submit(syncAsRunnable);
System.out.println("Runnable future result: " + f1.get());
// Callable: does the same work and returns the count
Callable<Integer> syncAsCallable = () -> WAREHOUSE_SKUS.size();
Future<Integer> f2 = executor.submit(syncAsCallable);
System.out.println("Callable future result: " + f2.get());
// Adapter: turn the Runnable into a Callable with a fixed result
Callable<String> adapted = Executors.callable(syncAsRunnable, "done");
System.out.println("Adapted callable result: " + executor.submit(adapted).get());
}
}
}
Runnable synced 4 SKUs Runnable future result: null Callable future result: 4 Runnable synced 4 SKUs Adapted callable result: done
How the code works
submit(Runnable)returns aFuture<?>. Itsget()returnsnullonce the task finishes, because a Runnable produces no value.submit(Callable)returns aFuture<Integer>, andget()returns the real count.Executors.callable(runnable, "done")wraps the Runnable so it can be used where a Callable is required. Running it prints the Runnable's message again and then returns the fixed result.- A single-thread executor runs the tasks one after another, so the output order is predictable.
4. Example: How Each One Handles a Checked Exception
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class FailureComparison {
static class SupplierOfflineException extends Exception {
private static final long serialVersionUID = 1L;
SupplierOfflineException(String message) {
super(message);
}
}
static int fetchStock() throws SupplierOfflineException {
throw new SupplierOfflineException("supplier API is offline");
}
public static void main(String[] args) throws InterruptedException {
try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
// Runnable must catch checked exceptions itself
Runnable runnable = () -> {
try {
fetchStock();
} catch (SupplierOfflineException e) {
System.out.println("Runnable handled it inside run(): " + e.getMessage());
}
};
executor.submit(runnable);
// Callable can simply let the checked exception escape
Callable<Integer> callable = FailureComparison::fetchStock;
Future<Integer> future = executor.submit(callable);
try {
future.get();
} catch (ExecutionException e) {
System.out.println("Callable reported it to the caller: " + e.getCause().getMessage());
}
}
}
}
Runnable handled it inside run(): supplier API is offline Callable reported it to the caller: supplier API is offline
How the code works
run()does not declare any exceptions, so the Runnable must catchSupplierOfflineExceptioninside its body. The caller never learns about the failure unless you add extra plumbing.call()declaresthrows Exception, so the method referenceFailureComparison::fetchStockcan let the checked exception escape.- The executor stores that exception in the
Future;get()rethrows it asExecutionExceptionwith the original as its cause.
5. When to Use Which
- Use
Runnablefor fire-and-forget work such as logging, sending a notification or refreshing a cache, where nobody waits for a value. - Use
Runnablewhen you start a plainThread, or when an API accepts only a Runnable, such asExecutor.execute(). - Use
Callablewhen the caller needs a result, for example a price, a count or a parsed document. - Use
Callablewhen the work calls methods that throw checked exceptions and the caller should decide how to handle them.
Both work with every executor. For the full picture of how tasks are submitted and run, see the Executor Framework tutorial.
6. Common Mistakes and Best Practices
- Expecting a value from a Runnable.
Future<?>.get()on a Runnable always returnsnull(or the fixed result you passed tosubmit(task, result)). - Hiding failures in a Runnable. An exception thrown from a Runnable passed to
submit()is stored in its Future and stays invisible unless someone callsget(). - Wrapping checked exceptions just to fit a Runnable. If the caller needs to know about the error, switch to a Callable instead.
- Ambiguous lambdas. A lambda that only throws, such as
() -> { throw new IllegalStateException(); }, fits both interfaces. Cast it or assign it to a typed variable to make your intent clear.
7. Summary
Runnable.run()returns nothing;Callable.call()returns a value of typeV.- Only
Callablecan throw checked exceptions to the caller. Threadaccepts onlyRunnable; executors accept both.Executors.callable()converts a Runnable into a Callable when an API needs one.
Related Tutorials
8. References
Frequently Asked Questions (FAQ)
Q1. Which is faster, Runnable or Callable?
Neither is meaningfully faster. Both are plain interfaces; the cost comes from the work inside them and from how the executor schedules it. Choose based on whether you need a result or checked exceptions.
Q2. Can a Callable be passed to execute()?
No. Executor.execute() accepts only a Runnable. Use ExecutorService.submit(), invokeAll() or invokeAny() for a Callable, or wrap it in a FutureTask.
Q3. Why does submit(Runnable) return a Future?
So that you can wait for the task, cancel it or see whether it failed. Its get() returns null on success, or the fixed result if you used submit(task, result).
Q4. Can a Runnable throw an exception?
It can throw unchecked exceptions such as IllegalStateException, but not checked ones, because run() declares no throws clause. Checked exceptions must be caught or wrapped inside run().
Q5. Is Callable a replacement for Runnable?
No. They solve different problems. Runnable remains the right choice for work that produces no result, and it is the only type a Thread accepts. Callable adds results and checked exceptions on top.