62,614
社区成员
发帖
与我相关
我的任务
分享
public static int getFinalResultPar(String s) throws FileNotFoundException,InterruptedException,ExecutionException{
ExecutorService executor = Executors.newFixedThreadPool(8);
Scanner scanner2 = new Scanner(new File(s));
int fR = 0;
List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
while(scanner2.hasNextLine()){
final Scanner lineScanner2 = new Scanner(scanner2.nextLine());
Callable<Integer> c = new Callable<Integer>() {
public Integer call() {
return getDivisorsSum(calSummedUpSum(calOneLine(lineScanner2)));
}
};
tasks.add(c);
}
List<Future<Integer>> futures = executor.invokeAll(tasks);
for (Future<Integer> fs: futures) {
int res = fs.get();
fR += res;
}
executor.shutdown();
return fR;
}