intermediateConcurrency Utilities

What is the difference between Callable and Runnable in Java?

Runnable's run() method returns void and cannot declare or throw any checked exception, so any error condition has to be handled entirely inside the method itself. Callable<T>'s call() method, by contrast, returns a value of type T and is declared to throw Exception, meaning both a real return value and any checked exception can propagate out through it. Both interfaces are functional interfaces, so as of Java 8 both can be written as lambda expressions. When you submit a Callable to an ExecutorService, you get back a Future<T> that you can use to retrieve the eventual result; if the Callable throws, that exception is wrapped inside an ExecutionException when you call get(), and you retrieve the original cause by calling getCause() on it.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to How does ReentrantLock differ from the synchronized keyword?← Back to all Java Concurrency & Multithreading questions