00:00

Runnable vs Callable in Java: Key Differences with Examples

Last updated:

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

FeatureRunnableCallable<V>
Packagejava.langjava.util.concurrent
IntroducedJava 1.0Java 5
Methodvoid run()V call() throws Exception
Returns a valueNoYes, of type V
Checked exceptionsMust be caught insideCan be thrown to the caller
Accepted by ThreadYesNo (wrap in FutureTask)
Accepted by ExecutorServiceexecute() and submit()submit(), invokeAll(), invokeAny()
Functional interfaceYesYes

2. Syntax

Declarations.java
// 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.

StockSyncComparison.java
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());
        }
    }
}
Output
Runnable synced 4 SKUs
Runnable future result: null
Callable future result: 4
Runnable synced 4 SKUs
Adapted callable result: done

How the code works

  1. submit(Runnable) returns a Future<?>. Its get() returns null once the task finishes, because a Runnable produces no value.
  2. submit(Callable) returns a Future<Integer>, and get() returns the real count.
  3. 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.
  4. 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

FailureComparison.java
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());
            }
        }
    }
}
Output
Runnable handled it inside run(): supplier API is offline
Callable reported it to the caller: supplier API is offline

How the code works

  1. run() does not declare any exceptions, so the Runnable must catch SupplierOfflineException inside its body. The caller never learns about the failure unless you add extra plumbing.
  2. call() declares throws Exception, so the method reference FailureComparison::fetchStock can let the checked exception escape.
  3. The executor stores that exception in the Future; get() rethrows it as ExecutionException with the original as its cause.

5. When to Use Which

  • Use Runnable for fire-and-forget work such as logging, sending a notification or refreshing a cache, where nobody waits for a value.
  • Use Runnable when you start a plain Thread, or when an API accepts only a Runnable, such as Executor.execute().
  • Use Callable when the caller needs a result, for example a price, a count or a parsed document.
  • Use Callable when 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 returns null (or the fixed result you passed to submit(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 calls get().
  • 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 type V.
  • Only Callable can throw checked exceptions to the caller.
  • Thread accepts only Runnable; executors accept both.
  • Executors.callable() converts a Runnable into a Callable when an API needs one.

Related Tutorials

8. References