对于我的工作,我必须开发一个小型 Java 应用程序来解析非常大的文本文件(~6800 kb),所以我正在尝试对其进行一些优化以进行进一步的处理。使用等号 (=) 分割线作为第一个分叉任务,并使用第二个分叉任务用逗号和一些计算进行分割。这将导致单个应用程序的多个分叉任务的良好性能。
1)第一次fork和join过程:
@Override
protected Map < String, String > compute() {
SplitString lineSplit = new SplitString();
Map < String, String > splitUrl = new HashMap < > ();
// list size is less than limit process actual task.
if (readAllLines.size() < Constant.LIMIT) {
// splitUrl map stores the splitter lines with equal_to
splitUrl = lineSplit.splittingLines(readAllLines);
} else { // list size greater than limit splits task in to two and process it.
// split task into sub task and stores it in list
List < String > left = readAllLines.subList(Constant.ZERO, readAllLines.size() / 2);
List < String > right = readAllLines.subList(readAllLines.size() / 2, readAllLines.size());
SplitTask firstTask = new SplitTask(left);
SplitTask secondTask = new SplitTask(right);
// forks the firstTask
firstTask.fork();
// forks the secondTask
secondTask.fork();
// join the task in splitUrl map
splitUrl.putAll(firstTask.join());
splitUrl.putAll(secondTask.join());
}
return splitUrl;
}
2)第二次fork和join过程:
@Override
protected Map < String, Map < String, Integer >> compute() {
SplitString ruleSplit = new SplitString();
Map < String, Map < String, Integer >> response = new HashMap < > ();
// list size is less than limit process actual task.
if (KeyList.size() < Constant.LIMIT) {
// splitUrl map stores the splitter lines with equal_to
response = ruleSplit.calculatingRuleTime(result, KeyList);
} else { // list size greater than limit splits task in to two and process it.
// split task into sub task and stores it in list.
List < String > left = KeyList.subList(Constant.ZERO, KeyList.size() / 2);
List < String > right = KeyList.subList(KeyList.size() / 2, KeyList.size());
SplitRuleTask firstTask = new SplitRuleTask(result, left);
SplitRuleTask secondTask = new SplitRuleTask(result, right);
// forks the firstTask
firstTask.fork();
// forks the firstTask
secondTask.fork();
// join the task in response map
response.putAll(firstTask.join());
response.putAll(secondTask.join());
}
return response;
}
谁能帮帮我?