Pour mon travail, je dois développer une petite application Java qui analyse de très gros fichiers texte (~ 6800 ko), donc j'essaie de l'optimiser un peu pour faire un autre processus. Séparer la ligne avec equalto (=) comme première tâche de fourche et pour diviser avec la virgule et quelques calculs en utilisant la deuxième tâche de fourche. Cela conduira-t-il à de bonnes performances avec plusieurs tâches de fourche pour une application unique.en utilisant plusieurs fork et rejoindre la classe pour diviser la tâche, est-ce une bonne pratique ou non?
1) et la fourche d'abord rejoindre processus:
@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) seconde fourche et processus de jointure:
@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;
}
quelqu'un peut-il s'il vous plaît aidez-moi?
Veuillez ne pas fournir de liens externes comme réponse –
Utilisation de Java Thread Pool ou fork et join pour des performances optimales? – usha
Fork Join pool donne de meilleures performances et une solution robuste lorsque vous avez une grande tâche, mais les frais généraux est plus dans ce cas. Vous devez jeter un oeil sur le travail de voler dans Fork/rejoindre la piscine. –