When to use Runnable vs Callable for multithreading
Explore the differences between Runnable and Callable interfaces in Java concurrent programming.
| Feature | Runnable | Callable |
|---|---|---|
| Return Value | void | V (Generic) |
| Exception | No checked exceptions | Can throw exceptions |
| Method | run() | call() |
| Package | java.lang | java.util.concurrent |
| Use with | Thread, ExecutorService | ExecutorService only |
// Runnable - No return value
Runnable task = () -> System.out.println("Running");
new Thread(task).start();
// Callable - Returns value
Callable<Integer> task = () -> 42;
Future<Integer> future = executor.submit(task);
int result = future.get();Java | Concurrency | ExecutorService | Future
Keywords: Java Runnable Callable Multithreading Concurrency Future ExecutorService