Callable
Stay organized with collections
Save and categorize content based on your preferences.
A task that returns a result and may throw an exception.
Implementors define a single method with no arguments called
call
.
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.
The Executors
class contains utility methods to
convert from other common forms to Callable
classes.
Public Method Summary
abstract
V
|
call()
Computes a result, or throws an exception if unable to do so.
|
Public Methods
public
abstract
V
call
()
Computes a result, or throws an exception if unable to do so.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["`Callable` is an interface defining a single method `call()` for tasks that return a result and may throw an exception."],["It is similar to `Runnable`, but allows for returning a result and throwing checked exceptions, suitable for execution by another thread."],["The `Executors` class provides methods to convert other forms into `Callable` classes."],["The `call()` method is responsible for computing a result and potentially throwing an exception if computation fails."]]],["The `Callable` interface defines a task that returns a result and may throw an exception. It has a single method, `call()`, which takes no arguments. Implementors define the `call()` method to compute a result. This method can throw an exception if the computation fails. Unlike `Runnable`, `Callable` returns a result and can throw checked exceptions. The `Executors` class offers conversion methods to `Callable`.\n"]]