Difference Between Runnable and Callable

RunnableCallable
If a Thread is not require to return anything after completing the job then we should use RunnableIf a Thread is required to return something after completing the job then we should use Callable.
Runnable interface in Java contains only one method: run()The callable interface in Java contains only one method: call()
Runnable jobs don’t return anything, Hence return type of run() is voidCallable jobs return something, Hence return type of call() is object.
If there is any chance of a checked exception in run() then it is compulsory that we have to handle that exception by using the try-catch block because we can not use the throws keyword for a run().If there is any chance of a checked exception in call() then we are not required to use try catch to handle that exception because call() already throws an exception.
The runnable interface is present inside java.lang package The callable interface is present in java. util.concurrent package
The runnable interface is introduced in Java 1.0vThe callable interface is introduced in Java 1.5v

Similar Java Tutorials

Leave a Comment