sjsxp
  1. sjsxp
  2. SJSXP-4

sjsxp in a multi-threaded environment

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      4

      Description

      I ran into an issue when running the StAX parser in a multi-threaded
      environment. The environment shares one single instance of XMLInputFactory and
      the reuse-instance property is enabled (ie the default setting). When creating
      and using XMLStreamReader instances from that singleton factory object, I get
      various errors (Scanner State 7 not Recognized, ArrayIndexOutOfBoundsException...).

      When I 1) set the reuse-instance property to false or 2) don't close the
      XMLStreamReader instances, everything seems to work correctly. Now, I would an
      of these options introduces a performance penalty as you can't reuse these
      instances and therefor have to create new XMLStreamReader instances when one is
      requested.

      Is this behaviour expected?

      Below is a small Java program reproducing the issue.

      public class StAXThreading implements Runnable {

      static int nrOfThreads = 10;

      static XMLInputFactory xif = XMLInputFactory.newInstance();

      static boolean ReuseInstance = true;

      static boolean CloseInstance = true;

      static URL xmlFile;

      public static void main(String[] args) {
      try {
      xif.setProperty("reuse-instance", Boolean.valueOf(ReuseInstance));
      xmlFile = xmlFile = new File("W:/XQuery/xqqa/creates/xml/ITEMS.xml").toURL();
      for (int ix = 0; ix < nrOfThreads; ix++)

      { Thread t = new Thread(new StAXThreading(), "StAX parsing thread #" + ix); t.setDaemon(false); t.start(); }

      System.out.println(Thread.currentThread().getName() + ": done");
      } catch (Exception e)

      { System.err.println(Thread.currentThread().getName() + ": exception:"); e.printStackTrace(); }

      }

      long begin, end;

      public void run() {
      try {
      begin = System.currentTimeMillis();
      do {
      XMLStreamReader xsr = xif.createXMLStreamReader(xmlFile.openStream());
      while (xsr.hasNext())

      { xsr.next(); }

      if (CloseInstance)

      { xsr.close(); }

      end = System.currentTimeMillis();
      } while ((end - begin) < 15000);
      } catch (Exception e)

      { System.err.println(Thread.currentThread().getName() + ": exception:"); e.printStackTrace(); }

      System.out.println(Thread.currentThread().getName() + ": done");
      }

      }

        Activity

        Hide
        Santiago Pericas-Geertsen added a comment -

        Unfortunately the XMLInputFactory implementation is not thread safe, as this is not demanded by the
        spec. Please re-open issue if bug still persists after synchronizing calls to the factory methods.

        Show
        Santiago Pericas-Geertsen added a comment - Unfortunately the XMLInputFactory implementation is not thread safe, as this is not demanded by the spec. Please re-open issue if bug still persists after synchronizing calls to the factory methods.

          People

          • Assignee:
            sjsxp-issues
            Reporter:
            wcordewiner
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: