java - ForkJoinPool 类的 execute() 方法

标签 java fork-join forkjoinpool

这是 API 的内容对此说道:

public void execute(Runnable task)

Description copied from interface: Executor
Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling

thread, at the discretion of the Executor implementation.

Parameters:
    task - the runnable task
Throws:
    NullPointerException - if the task is null
    RejectedExecutionException - if the task cannot be scheduled for execution

ForkJoinPool 已经是 ExecutorService 的实现?他们在说什么?我如何知道这种方法的行为?

最佳答案

我不太确定你在这里问什么,但是ForkJoinPoolExecutorService的实现。 execute(Runnable) 方法将安排由 ForkJoinPool 执行的任务。当池中的工作线程可以自由执行此类任务时,将执行此任务。它本质上与 submit(Runnable) 相同,只是它不返回 ForkJoinTask (事实上,如果您检查源代码,您会发现这两种方法执行相同的操作)事情,除了 execute 不返回它提交的任务)。

关于java - ForkJoinPool 类的 execute() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17881715/

相关文章:

java - 工作线程 "steal"如何从另一个工作线程?

java - Else If 和 Do while 没有按预期工作

java - Spring 应用程序上下文 : access web. xml 上下文参数?

system-verilog - SystemVerilog fork/join w/ "run()"类型函数和 SystemC

java - 我如何知道 Java 中的 Fork 和 Join 是否有足够的池大小?

java - 在并行流上调用顺序使所有先前的操作顺序

java - 使用 DataInputStream 和 DataOutputStream 以及套接字的管道损坏

java - 我需要帮助更改 java 中的文本文件

Angular Observable HttpInterceptor ForkJoin 不起作用

concurrency - 为什么parallelStream 使用的是ForkJoinPool,而不是普通的线程池?