title: How to read all lines of a file in parallel in Java 8
body: <p>I want to read all lines of a 1 GB large file as fast as possible into a <code>Stream&lt;String&gt;</code>. Currently I'm using <code>Files(path).lines()</code> for that. After parsing the file, I'm doing some computations (<code>map()</code>/<code>filter()</code>).</p>
  
  <p>At first I thought this is already done in parallel, but it seems I'm wrong: when reading the file as it is, it takes about 50 seconds on my dual CPU laptop. However, if I split the file using bash commands and then process them in parallel, it only takes about 30 seconds.</p>
  
  <p>I tried the following combinations:</p>
  
  <ol>
  <li>single file, no parallel lines() stream ~ 50 seconds</li>
  <li>single file, <code>Files(..).lines().parallel().[...]</code> ~ 50 seconds</li>
  <li>two files, no parallel lines() strean ~ 30 seconds</li>
  <li>two files, <code>Files(..).lines().parallel().[...]</code> ~ 30 seconds</li>
  </ol>
  
  <p>I ran these 4 multiple times with roughly the same results (by 1 or 2 seconds). The <code>[...]</code> is a chain of map and filter only, with a <code>toArray(...)</code> at the end to trigger the evaluation. </p>
  
  <p>The conclusion is that there is no difference in using <code>lines().parallel()</code>. As reading two files in parallel takes a shorter time, there is a performance gain from splitting the file. However it seems the whole file is read serially.</p>
  
  <p><strong>Edit:</strong><br>
  I want to point out that I use an SSD, so there is practically no seeking time. The file has 1658652 (relatively short) lines in total.
  Splitting the file in bash takes about 1.5 seconds:</p>
  
  <pre><code>   time split -l 829326 file # 829326 = 1658652 / 2
     split -l 829326 file  0,14s user 1,41s system 16% cpu 9,560 total
  </code></pre>
  
  <p>So my question is, is there any class or function in the Java 8 JDK which can parallelize reading all lines without having to split it first? For example, if I have two CPU cores, 
  the first line reader should start at the first line and a second one at line <code>(totalLines/2)+1</code>.</p>