日期:2014-05-20 浏览次数:21136 次
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; }