b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

forkjoinpool_completablefuture_forkjoinpool源码分析(2)

电脑杂谈  发布时间:2017-04-10 14:30:59  来源:网络整理

In this example, you have created a ForkJoinPool object and a subclass of the

ForkJoinTask class that you execute in the pool. To create the ForkJoinPool object,

you have used the constructor without arguments, so it will be executed with its default

configuration. It creates a pool with a number of threads equal to the number of processors

of the computer. When the ForkJoinPool object is created, those threads are created and

they wait in the pool until some tasks arrive for their execution.

Since the Task class doesn't return a result, it extends the RecursiveAction class. In the

recipe, you have used the recommended structure for the implementation of the task. If the

task has to update more than 10 products, it divides those set of elements into two blocks,

creates two tasks, and assigns a block to each task. You have used the first and last

attributes in the Task class to know the range of positions that this task has to update in the

list of products. You have used the first and last attributes to use only one copy of the

products list and not create different lists for each task.

To execute the subtasks that a task creates, it calls the invokeAll() method. This is a

synchronous call, and the task waits for the finalization of the subtasks before continuing

(potentially finishing) its execution. While the task is waiting for its subtasks, the worker thread

that was executing it takes another task that was waiting for execution and executes it. With

this behavior, the Fork/Join framework offers a more efficient task management than the


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-40525-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 杨宁宁
      杨宁宁

      #吴亦凡1106生日快乐#

    每日福利
    热点图片
    拼命载入中...