- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between Runnable and Callable interface in java
Runnable and Callable both functional interface. Classes which are implementing these interfaces are designed to be executed by another thread.
Thread can be started with Ruunable and they are two ways to start a new thread: one is by subclassing Thread class and another is implementing Runnable interface.
Thread class does not have constructor for callable so we should use ExecutorService class for executing thread.
Sr. No. | Key | Runnable | Callable |
---|---|---|---|
1 | Package | It belongs to Java.lang | It belongs to java.util.concurrent |
2 | Thread Creation | We can create thread by passing runnable as a parameter. | We can’t create thread by passing callable as parameter |
3 | Return Type | Ruunable does not return anything | Callable can return results |
4. | Method | It has run() method | It has call()method |
5 | Bulk Execution | It can’t be used for bulk execution of task | It can be used for bulk execution of task by invoking invokeAll(). |
Example of Runnable
public class RunnableExample implements Runnable { public void run() { System.out.println("Hello from a Runnable!"); } public static void main(String args[]) { (new Thread(new RunnableExample())).start(); } }
Example of Callable
public class Main { public static void main(String args[]) throws InterruptedException, ExecutionException { ExecutorService services = Executors.newSingleThreadExecutor(); Future<?> future = services.submit(new Task()); System.out.println("In Future Object" + future.get()); } } import java.util.concurrent.Callable; public class Task implements Callable { @Override public String call() throws Exception { System.out.println("In call"); String name = "test"; return name; } }
- Related Articles
- Difference Between Thread Class and Runnable Interface in Java
- Difference between Thread and Runnable in Java
- What is Runnable interface in Java?
- What is Callable interface in Java?
- Difference Between Class and Interface in Java
- Difference between Abstract Class and Interface in Java
- Difference Between Iterator and Enumeration Interface in Java
- How to implement the Runnable interface using lambda expression in Java?
- Difference Between Interface and Abstract Class in Java & C#
- How to create a thread without implementing the Runnable interface in Java?
- Difference between default and static interface method in Java 8.
- Callable and Future in Java
- What is the difference between Enumeration interface and enum in Java?
- Difference between peek(), poll() and remove() method of Queue interface in java?
- Difference between abstract class and interface

Advertisements