Home » Java Executors callable() Method with Examples

Java Executors callable() Method with Examples

by Online Tutorials Library

Java Executors Callable() Method

The Callable() method of Executors class returns a Callable object that, when called, runs the given task and returns null.

Syntax

Parameters

task – the task to run

result – the result to return

action – the privileged action to run

Return

a callable object

Throw

NullPointerException

Example 1

Test it Now

Output:

Sun Mar 17 02:29:46 IST 2019::pool-1-thread-1  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-2  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-3  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-4  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-5  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-6  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-7  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-8  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-9  Sun Mar 17 02:29:48 IST 2019::pool-1-thread-10  

Example 2

Test it Now

Output:

::pool-1-thread-1  ::pool-1-thread-2  ::pool-1-thread-3  ::pool-1-thread-4  ::pool-1-thread-5  
Next TopicJava Executors

You may also like