title: Threading issue in pdfbox during image generation
body: <p>I am trying to extract image metadata (and the image) for images embedded in pdfs, using pdfbox. I have the following problem,</p>
  
  <pre><code>for each page i:
   for each image j in page i:
    extract metadata, output
    create the image file in separate thread
  </code></pre>
  
  <p>Now, I have the following code for creating the image file, which is included in a method called <code>generate_image()</code> in <code>FileWriting</code>class implementing <code>Runnable</code>. This method is called from <code>run()</code>. The code follows:</p>
  
  <pre><code>try {
      File F=new File(figurename);
      item.getImage().write2file( F );
  
  
  } catch (Exception e) {
      e.printStackTrace();
  } 
  </code></pre>
  
  <p>where <code>item.getImage()</code> returns a <code>PDXObjectImage</code> object. If I do this without creating a separate thread, it works fine, but when I create a thread to do this task, it shows following error:</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Index: 5, Size: 0
  at java.util.ArrayList.rangeCheck(ArrayList.java:604)
  at java.util.ArrayList.get(ArrayList.java:382)
  at org.apache.pdfbox.io.RandomAccessBuffer.seek(RandomAccessBuffer.java:84)
  at org.apache.pdfbox.io.RandomAccessFileInputStream.read(RandomAccessFileInputStream.java:96)
  at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
  at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
  at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
  at java.io.FilterInputStream.read(FilterInputStream.java:107)
  at org.apache.pdfbox.pdmodel.graphics.xobject.PDCcitt$TiffWrapper.read(PDCcitt.java:468)
  at org.apache.pdfbox.io.IOUtils.copy(IOUtils.java:68)
  at org.apache.pdfbox.pdmodel.graphics.xobject.PDCcitt.write2OutputStream(PDCcitt.java:184)
  at org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage.write2file(PDXObjectImage.java:165)
  at extractor.FileWriting.generate_image(FileWriting.java:136)
  </code></pre>
  
  <p>Can anyone please point out where I am going wrong?</p>