title: How to parallelize a method and write results to file?
body: <p>I'm already looking for a solution for quite a while, but I'm still struggling with concurrency and parallelization. </p>
  
  <p>Background: There's an ETL process and I get a big csv (up to over a million rows). In production there will be live updates, too. I want to spell check each row. For that I use an adapted <a href="https://languagetool.org/development/api/" rel="nofollow noreferrer">LanguageTool</a>. The check method (with my customization inside) takes quite a while. I want to speed it up. </p>
  
  <p>One aspect is of course the method itself, but I also want to simply check multiple rows at a time. The order of the rows is not important. The result is the corrected text and it should be written to a new csv file for further processing.</p>
  
  <p>I found that <code>ExecutorService</code> might be a reasonable choice, but since I'm not that familiar with it, some help would be appreciated.</p>
  
  <p>That's how I use it so far in the ETL process:</p>
  
  <pre><code>private static SpellChecker spellChecker;
  static {
      SpellChecker tmp = null;
      try {
        tmp = new SpellChecker(...);
      } catch (Exception e) {
          e.printStackTrace();
      }
      spellChecker = tmp;
    }
  
  public static String spellCheck(String input) {
      String output = input.replace("&lt;/li&gt;", ".");
      output = searchAVC.removeHtml(output);
      try {
          output = spellChecker.correctText(output);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return output;
  }
  </code></pre>
  
  <p>My spellChecker is a custom library here and I create a static object of it (because instanciation of LanguageTool takes some time). 
  I want to parellize the execution of <code>spellCheck</code>.</p>
  
  <p>I've already read stuff like this:
  <a href="https://www.airpair.com/java/posts/parallel-processing-of-io-based-data-with-java-streams" rel="nofollow noreferrer">https://www.airpair.com/java/posts/parallel-processing-of-io-based-data-with-java-streams</a>
  <a href="https://stackoverflow.com/questions/2016083/what-is-the-easiest-way-to-parallelize-a-task-in-java">What is the easiest way to parallelize a task in java?</a>
  <a href="https://stackoverflow.com/questions/10027020/write-to-text-file-from-multiple-threads">Write to text file from multiple threads?</a></p>
  
  <p>I don't really know to combine all this information. What do I have to concern when reading the file? Writing the file? Processing the rows?</p>