Java Executors Callable() 方法

2025 年 3 月 25 日 | 阅读 2 分钟

Executors 类的 Callable() 方法返回一个 Callable 对象,当被调用时,它会运行给定的任务并返回 null。

语法

参数

task - 要运行的任务

result - 要返回的结果

action - 要运行的特权操作

返回

一个可调用对象

Throw

NullPointerException

示例 1

输出

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

示例 2

输出

::pool-1-thread-1
::pool-1-thread-2
::pool-1-thread-3
::pool-1-thread-4
::pool-1-thread-5
下一主题Java Executors