The Java interfaces of Runnable and Callable are both used to define a task that can be executed by a thread, but they have some differences:
Return Value: The Runnable interface does not return any value, whereas the Callable interface allows the task to return a result.
Exception Handling: The run() method of Runnable does not throw any checked exceptions, while the call() method of Callable throws checked exceptions.
Implementation: The Runnable interface is implemented using the run() method, while the Callable interface is implemented using the call() method.
Usage: Runnable is typically used for simple tasks that do not need to return any value, while Callable is used when a task requires a return value or when exceptions need to be handled explicitly.
Asked: 2022-02-07 11:00:00 +0000
Seen: 11 times
Last updated: Jul 24 '21