"The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception."
Runnable | Callable |
Introduced in Java 1.0 | Introduced in Java 1.5 as part of java.util.concurrent library |
Runnable cannot be parametrized | Callable is a parametrized type whose type parameter indicates the return type of its run method |
Classes implementing Runnable needs to implement run() method | Classes implementing Callable |
Runnable.run() returns no Value | Callable |
Can not throw Checked Exceptions | Can throw Checked Exceptions |
public class RunnableTest implements Runnable { @Override public void run() { //any processing } } | import java.util.concurrent.Callable; public class CallableTest implements Callable |
No comments:
Post a Comment