Difference between Callable and Runnable interface
in Java is one of the interesting question from my list of Top
15 Java multi-threading questions, and it’s also very popular in various
Java Interviews. Callable interface is newer than Runnable interface
and added on Java 5 release along with other major changes e.g. Generics,
Enum,
Static
imports and variable
argument method. Though both Callable and Runnable interface
are designed to represent task, which can be executed by any thread, there is
some significant difference between them. In my opinion, major difference between Callable and Runnable interface is that Callable can return
result of operation performed inside call() method,
which was one of the limitation with Runnable interface.
Another significant difference between Runnable and Callable interface
is ability to throw checked
exception. Callable interface can throw checked
exception because it's call method throws Exception. By the way sometime
this question is also asked as follow-up question of another classic difference
between Runnable and Thread in Java. Commonly FutureTask is used
along with Callable to get result of asynchronous
computation task performed in call() method.