Skip to main content

Runnable vs Callable interfaces in Java

The Runnable interface is the most widely used interface in Java to provide multithreading features, to execute tasks parallelly.

The Callable interface is the improvised version of the Runnable interface, this interface is introduced since Java 1.5.

Runnable interface:
public interface Runnable
void run()

When to Use Runnable:
If the developer just wants to fire any operation and not depending on the result, then we can just use Runnable. Callable Interface returns result from the thread execution or return null.

Callable Interface:
Public interface Callable
V call() throws Exception
Computes a result, or throws an exception if unable to do so.
The Callable interface works along with Future class, we can get the result using the future object, using get() method. So once we submit thread with the call() method, it will wait until getting the result from the thread.





Comments