public class TreeTaskextends RecursiveTask {
private StringactivityCode;
private ActivityMapperactivityMapper = SpringContextHolder.getBean(ActivityMapper.class);
public TreeTask(String activityCode) {
this.activityCode = activityCode;
}
@Override
protected List compute() {
List result = Lists.newArrayList();
List ruleActivityList =activityMapper.querySonActivity(activityCode);
List> forks = Lists.newArrayListWithExpectedSize(ruleActivityList.size());
for(Activity activity:ruleActivityList){
result.add(activity);
TreeTask treeTask =new TreeTask(activity.getActivityCode());
forks.add(treeTask);
treeTask.fork();
}
for( RecursiveTask tasks:invokeAll(forks)){
result.addAll(tasks.join());
}
return result;
}
public static void main(String[] args) {
String activityCode ="";
TreeTask treeTask =new TreeTask(activityCode);
ForkJoinPool forkJoinPool =new ForkJoinPool();
List activities = forkJoinPool.invoke(treeTask);
}
}