Is the library thread safe?

  • Andrea Vacondio

    Andrea Vacondio - 2009-01-10

    I'm using multiple thread to concurrently create a thumbnail view of the document, everything works fine with a single thread but rising the number I'm getting the following exception for some pages (randomly, not always the same pages) so I'm wondering if I'm missing something and my code is broken or if the library is not thread safe.
    Thank you

    15:32:22,464 ERROR JPodThumbnailCreator$ThumnailCreator  Unable to generate thumbnail
    de.intarsys.pdf.content.CSError: unexpected exception
        at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
        at de.intarsys.pdf.content.CSDeviceBasedInterpreter.process(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
        at java.util.concurrent.ThreadPoolExecutor$
    Caused by: java.lang.IndexOutOfBoundsException
        at java.nio.Buffer.checkIndex(
        at java.nio.DirectByteBuffer.getInt(
        at de.intarsys.nativec.jna.JnaNativeHandle.getInt(
        at de.intarsys.nativec.type.NativeObject.getInt(
        at de.intarsys.cwt.freetype.Outline.getPointX(
        at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeGlyphs.createContour(Unknown Source)
        at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeGlyphs.createShape(Unknown Source)
        at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeGlyphs.getShape(Unknown Source)
        at de.intarsys.pdf.platform.cwt.font.freetype.FreetypeGlyphs.render(Unknown Source)
        at de.intarsys.pdf.platform.cwt.rendering.CSPlatformDevice.basicTextShowGlyphs(Unknown Source)
        at de.intarsys.pdf.content.CSBasicDevice.textShow(Unknown Source)
        at de.intarsys.pdf.platform.cwt.rendering.CSPlatformDevice.textShow(Unknown Source)
        at de.intarsys.pdf.content.CSDeviceBasedInterpreter.render_TJ(Unknown Source)
        at de.intarsys.pdf.content.CSInterpreter.process(Unknown Source)
        ... 6 more

    • mtraut

      mtraut - 2009-01-12

      jPod is intended to be thread safe for certain scenarios. For example, read - access to a document is thread safe (which is not understood, as data is read lazy). Changing the document structure needs external synchronization (e.g. writing to COSDictionary).

      Rendering the document *should* be thread safe (as this is a reading scenario), but for sure you have to use different interpreter instances. We have overseen the bottleneck of the unique, lazy implemented Freetype contours, shared by the interpreters. We will review the code with respect to this.

      For your issue at the moment it should be enough to synchronize de.intarsys.pdf.platform.cwt.font.freetype.FreetypeGlyphs.createShape and  de.intarsys.pdf.platform.cwt.font.freetype.FreetypeGlyphs.init

    • mtraut

      mtraut - 2009-01-13

      so sorry - one should not answer immediately.

      synchronizing this methods won't help, as the shared resource is the font's native interface, not the lazy glyph. you should apply

          protected Shape createShape() {
              synchronized (font) {


          private void init() throws PlatformFontException {
              synchronized (font) {

      to make outline access safe.

    • Andrea Vacondio

      Andrea Vacondio - 2009-01-20

      Tested and the exception went away :)
      Will you include this in the next release?


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks