import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ExecutionException; // A class that implements Callable class WordLengthCallable implements Callable { private final String word; public WordLengthCallable(String word) { this.word = word; } @Override public Integer call() { // Returning the length of the word return word.length(); } } public class CallableExample { public static void main(String[] args) { // Creating a thread pool with one thread ExecutorService executor = Executors.newSingleThreadExecutor(); // Creating a callable object WordLengthCallable callable = new WordLengthCallable("Hello, World"); // Submitting the callable to the executor and getting a Future object Future future = executor.submit(callable); try { // Getting the result from the Future object int length = future.get(); System.out.println("Length of the word: " + length); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } // Shutting down the executor executor.shutdown(); } }