How to use the java Fork/Join framework
This article introduces the relevant knowledge of "how to use the java Fork/Join framework". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The Fork/Join framework highlights:
1. If necessary, fork a large task into several sub-tasks (so that it can no longer be split, that is, the critical value of the split), and then summarize the results of each small task by join.
(2) the "work stealing mode" is adopted in the Forkhand join.
3ForkJoin makes more effective use of CPU resources.
4Jing Java 8 optimizes parallel flows, and Stream API can declaratively switch between parallel and serial flows through parallel () and sequential ().
Here is a simple example:
Public class ForkJoinWorkTest extends RecursiveTask {private Long start; private Long end; public static final Long critical = 100000L; public ForkJoinWorkTest (Long start, Long end) {this.start = start; this.end = end;} @ Override protected Long compute () {Long length = end-start; if (length)