什么是 ForkJoin
ForkJoin 在 JDK 1.7 , 并行执行任务!提高效率。大数据量!
ForkJoin处理流程:工作窃取
试验代码:
MyForkJoinTask:
package icu.lookyousmileface.forkjoin;import java.util.concurrent.RecursiveTask;class MyForkJoinTask extends RecursiveTask
MainTask:
package icu.lookyousmileface.forkjoin;import java.util.concurrent.ExecutionException;import java.util.concurrent.ForkJoinPool;import java.util.concurrent.ForkJoinTask;import java.util.stream.LongStream;public class MainTask { public static void main(String[] args) throws ExecutionException, InterruptedException { //创建forkjoin池// ForkJoinPool forkJoinPool = new ForkJoinPool();// //创建自己的ForkJoin计算程序// ForkJoinTask forkJoinTask = new MyForkJoinTask(0L, 10_0000_0000L);// //提交计算任务// ForkJoinTask
试验代码:
package icu.lookyousmileface.completables;import java.util.concurrent.CompletableFuture;import java.util.concurrent.ExecutionException;import java.util.concurrent.TimeUnit;public class CompletableUse { public static void main(String[] args) throws ExecutionException, InterruptedException {// //没有返回值的异步回调// CompletableFuture