title: Unable to figure out the correct data structure and correct approach in this scenario of parsing text
body: <p>I am working on a text document parsing application. </p>
  
  <p>The design of the document is as shown in the figure <img src="https://i.stack.imgur.com/TQzeL.jpg" alt="figure"></p>
  
  <p>Here is how the parsing is being done:</p>
  
  <ol>
  <li><p>Document contains an ArrayList of pages
  .</p></li>
  <li><p>Each page has a <strong><code>Map&lt;float, List&lt;Character&gt;&gt;</code></strong></p></li>
  </ol>
  
  <p>the <code>float</code> value contains the yaxis value of a character location and hence a <code>key</code> and Character contains other informations.</p>
  
  <p>Parsing is done character by character via third party library.  Please add comments if more information is required.</p>
  
  <p>Now while parsing I have created two ExecutorService thread pools, one for pages and one for populating map.</p>
  
  <p>I initially create a Document and pass each page to the <code>page parser</code> as a runnable to <code>ExecutorService</code>. Which in turn passes an <code>empty map</code> to text parser.</p>
  
  <p>Text parser checks if the <code>map</code> has a key value
     if yes it adds the character to the list or a new list what ever is necessary.</p>
  
  <p>Problem here is that this task can be done concurrently for all pages to speed up execution. But I am unable to do with this data structure as all threads stuck in between if parsed normally and if done in a synchronized fashion using <code>Collections.synchronizedMap</code> , takes a lot of time.</p>
  
  <p>Also, I am maintaining two different lists of Future objects to check if the threads finished.  </p>
  
  <p>Kindly provide valuable suggestions for improvements and concurrent execution to speed up the execution.</p>