Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The principle of forkjoin in Java and how to apply forkjoin

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the principle of forkjoin in Java and how to apply forkjoin related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe everyone read this article in Java forkjoin principle and forkjoin how to apply the article will have a harvest, let's take a look at it.

ForkJoinTask is each task in ForkJoinPool. It has two main subclasses: RecursiveAction and RecursiveTask. Then assign tasks to perform tasks through fork() method, and summarize task results through join() method

This is how the whole process works. It has two subclasses, both of which can be used to implement our task allocation and calculation.

(1) RecursiveAction A recursively fruitless ForkJoinTask (no return value)

(2) Recursive Task A recursive ForkJoinTask with results (with return values)

ForkJoinPool: contains a workQueue queue;

workQueues: references to ForkJoinPool by ForkJoinTask array and workerThread;

ForkJoinTask array is responsible for storing tasks submitted by programs to ForkJoinPool, while workerThread array is responsible for executing these tasks. The reference to ForkJoinPool is to obtain tasks again and hand them to workerThread for processing after the tasks in ForkJoinTask array are processed.

Knowledge Point Extension: Java Concurrent Fork-Join Framework Principle Analysis

What is a Foirk/Join Framework?

Fork/Join framework is a framework provided by Java 7 for parallel execution of tasks. It is a framework that divides a large task into several small tasks and finally summarizes the results of each small task to obtain the results of a large task.

2. What is parallel flow and sequential flow 2.1 What is parallel flow?

Parallel streaming is a stream that divides a content into multiple data blocks and processes each data block separately with different threads.

2.2 Job theft mode

A thread steals tasks from other queues to execute

Using the Fork/Join Framework

/** * */public class ForkJoinCalculate extends RecursiveTask { /** * */ private static final long serialVersionUID = 7125244951292834932L; private long start;//start value private long end;//End value private static final long THRESHOLD = 10000L;//Threshold @Override protected Long compute() { long length = end - start; if(length

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report