Java通过Fork/Join优化并行计算
本文实例为大家分享了Java通过Fork/Join优化并行计算的具体代码,供大家参考,具体内容如下
Java代码:
packageThreads;
importjava.util.concurrent.ForkJoinPool;
importjava.util.concurrent.RecursiveAction;
/**
*CreatedbyFrank
*/
publicclassRecursiveActionDemoextendsRecursiveAction{
staticint[]raw={19,3,0,-1,57,24,65,Integer.MAX_VALUE,42,0,3,5};
staticint[]sorted=null;
int[]source;
int[]dest;
intlength;
intstart;
finalstaticintTHRESHOLD=4;
publicstaticvoidmain(String[]args){
sorted=newint[raw.length];
ForkJoinPoolpool=newForkJoinPool();
pool.invoke(newRecursiveActionDemo(raw,0,raw.length,sorted));
System.out.println('[');
for(inti:sorted){
System.out.println(i+",");
}
System.out.println(']');
}
publicRecursiveActionDemo(int[]source,intstart,intlength,int[]dest){
this.source=source;
this.dest=dest;
this.length=length;
this.start=start;
}
@Override
protectedvoidcompute(){
System.out.println("ForkJoinDemo.compute()");
if(length
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短