Пример #1
0
  public static void main(String[] args) throws Exception {
    parseArguments(args);

    List<Iterator<String>> segments = Splitter.split(inputFilePath, numberOfThreads);

    List<Future<Analytic>> futures = new ArrayList<Future<Analytic>>(segments.size());
    ExecutorService threadPool = Executors.newFixedThreadPool(segments.size());
    for (final Iterator<String> segment : segments) {
      Future<Analytic> future =
          threadPool.submit(
              new Callable<Analytic>() {
                @Override
                public Analytic call() throws Exception {
                  return new Analyzer(segment).parse();
                }
              });
      futures.add(future);
    }

    try {
      ArrayList<Analytic> analytics = new ArrayList<Analytic>(futures.size());
      for (Future<Analytic> future : futures) {
        analytics.add(future.get());
      }
      Analytic result = Synthesizer.synthesize(analytics);
      writeResult(result);
    } finally {
      threadPool.shutdown();
    }
  }