---
title: "What is the difference between Callable and Runnable in Java?"  
description: "What is the difference between Callable and Runnable in Java?"  
author: "Revati S Misra"  
published: 2024-07-19  
updated: 2024-07-19  
canonical: https://www.mindstick.com/forum/160962/what-is-the-difference-between-callable-and-runnable-in-java  
category: "java"  
tags: ["java", "programming language", "functions"]  
reading_time: 3 minutes  

---

# What is the difference between Callable and Runnable in Java?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between Callable and [Runnable](https://www.mindstick.com/forum/23202/difference-between-implements-runnable-and-extends-thread) in Java?

## Replies

### Reply by Ashutosh Patel

#### Difference Between Callable and Runnable

Both Callable and Runnable are interfaces for describing tasks that can be executed simultaneously, usually by threads. Here is the main difference between Callable and Runnable.

#### Return Value

**Runnable-** The `run()` method of the Runnable interface does not return a result. A null method, means that it executes an event but returns no value.

**Callable-** The `call()` method of the Callable interface returns a result of the specified type (specified by the generic type parameter `<V>`). The `call()` method can throw checked exceptions, which must be handled or thrown or declared.

#### Handling Exception

**Runnable-** the `run()` method in Runnable cannot directly throw a noted exception. If it needs to throw a checked exception, it should be caught in the `run(`) method and handled accordingly.

**Callable-** the `call()` method in Callable can throw a flagged exception. These exceptions must be caught in the `call()`method or declared in the `throws` clause of the method.

#### Usage with ExecutorService

Both the Runnable and the Callable can be passed to the ExecutorService for execution at the same time.

## Example-

## Runnable Syntax-

```java
Runnable task = () -> {
   // Task implementation
};
executorService.submit(task);
```

## Example-

```java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class RunnableExample {
   public static void main(String[] args) {
       ExecutorService executorService = Executors.newSingleThreadExecutor();
       // Runnable task
       Runnable task = () -> {
           try {
               Thread.sleep(2000);  // Simulate some task
               System.out.println("Runnable task completed");
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       };
       // Submit the task to the executor service
       executorService.submit(task);
       // Shutdown the executor service after task completion
       executorService.shutdown();
   }
}
```

## Callable Syntax-

```java
Callable<Integer> task = () -> {
   // Task implementation that returns a result
   return someResult;
};
Future<Integer> future = executorService.submit(task);
```

## Example-

```java
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class CallableExample {
   public static void main(String[] args) {
       ExecutorService executorService = Executors.newSingleThreadExecutor();
       // Callable task
       Callable<Integer> task = () -> {
           Thread.sleep(3000);  // Simulate some time-consuming task
           return 42;  // Return a result
       };
       // Submit the task to the executor service
       Future<Integer> future = executorService.submit(task);
       try {
           // Wait for the task to complete and get the result
           Integer result = future.get();
           System.out.println("Callable task completed, result: " + result);
       } catch (Exception e) {
           e.printStackTrace();
       }
       // Shutdown the executor service after task completion
       executorService.shutdown();
   }
}
```

#### \
Return Value Handling

**Runnable-** Since Runnable doesn’t return a value, you typically use a separate tool (such as a shared variable or some other synchronization technique) if you need to get a result or condition after a task is complete

**Callable-** When a Callable completes its execution, it returns a Future object that can be used to retrieve a statistic or to handle exceptions thrown during its execution.

Callable is an improvement over Runnable that lets functions return values ​​and throw checked exceptions, providing greater flexibility in concurrent programming scenarios

**Also, Read:** [How to achieve thread-safety in Java?](https://www.mindstick.com/forum/160963/how-to-achieve-thread-safety-in-java)


---

Original Source: https://www.mindstick.com/forum/160962/what-is-the-difference-between-callable-and-runnable-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
