![]() |
The ExecutorService interface in Java offers a strong management and control mechanism for asynchronous task execution. The InvokeAny() method is one of the helpful methods provided by this interface. This lets us submit numerous tasks and provides the outcome of the first one that is finished successfully. In this article, we will learn how to use the ExecutorService.invokeAny method in Java. Approaches to use the ExecutorService.invokeAny method
Program to Use the ExecutorService.invokeAny Method in JavaBelow is the code implementation of the above-mentioned approaches. Approach 1: Basic Usage without TimeoutBelow is the Program to use the ExecutorService.invokeAny method without timeout: Java
Output
Result: Result from Task 3 Explanation of the above Program:
Approach 2: Usage with TimeoutBelow is the Program to use the ExecutorService.invokeAny method with timeout: Java
Output
Result: Result from Task 2 Explanation of the above Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |