谁能解释一下 jdk 1.7 中引入的 ForkJoinWorkerThread 的优点和特性,或者建议一个解释这些特性的链接。
我试图在 Oracle 和 Goolge 上找到它的工作示例,但找不到。
谢谢。
最佳答案
您不应该使用ForkJoinWorkerThread
。使用ForkJoinPool反而。更具体地说,唯一可见的构造函数是 protected ,因此除非您有意对其进行子类化,否则您无需担心。
来自api
A thread managed by a ForkJoinPool, which executes ForkJoinTasks. This class is subclassable solely for the sake of adding functionality -- there are no overridable methods dealing with scheduling or execution. However, you can override initialization and termination methods surrounding the main task processing loop. If you do create such a subclass, you will also need to supply a custom ForkJoinPool.ForkJoinWorkerThreadFactory to use it in a ForkJoinPool.
您真的需要实现它吗?
I am trying to find its working example on Oracle and Goolge but not able to find one.
如果您使用 ForkJoinPool并且需要重写 ThreadFactory,您需要实现 ForkJoinWorkerThread 并将其作为构造函数参数传递。
public ForkJoinPool(int parallelism,
ForkJoinPool.ForkJoinWorkerThreadFactory factory,
Thread.UncaughtExceptionHandler handler,
boolean asyncMode)
关于java - ForkJoinWorkerThread的特点和优点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15339094/