GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — Callable vs Future in Java - GeeksforGeeks Callable vs Future in JavaLast Updated : 25 Apr, 2026 In Java, multithreading allows tasks to run concurrently, improving performance and responsiveness. Traditionally, developers used the Runnable interface to define tasks, but it has two major limitations: it cannot return a result and cannot throw checked exceptions. To overcome these, Java introduced the Callable and Future interfaces in Java 5.
Callable InterfaceThe Callable interface represents a task that can return a result and throw checked exceptions. It is an alternative to Runnable when a task needs to produce an output.
Output Result: 15 Explanation: A Callable task is submitted to the executor. It calculates the sum of numbers from 1 to 5 and returns the result. The result is retrieved using future.get() after the task finishes. Future InterfaceThe Future interface represents the outcome of an asynchronous task and allows you to interact with it after submission to an ExecutorService.
Output Result: 30 Explanation: This code creates a single-thread executor to run a task asynchronously using Callable. The task calculates the sum of 10 and 20, and the result is stored in a Future object. Using future.get(), the program retrieves the result (30), and finally shuts down the executor to free resources. Callable vs FutureTable showing difference between callable and future.
Comment Explore | ||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |