Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2117

OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 2.6
    • 2.7
    • Xalan
    • Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.)
    • None
    • generic

    Description

      This simple program causes an OutOfMemoryError in a few seconds due to the thread local cache of SAXParser instances (see XmlReaderManager class).

      The problem is particularly annoying when threads are often created (because the server is under heavy load, because application exceptions kill existing threads, because applications create short live threads in which to perform transformations, because...)

      ---------------------------------------------------------------------
      import javax.xml.transform.Source;
      import javax.xml.transform.Transformer;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.TransformerFactoryConfigurationError;
      import javax.xml.transform.stream.StreamResult;
      import javax.xml.transform.stream.StreamSource;

      public class Prova
      {

      public static void main (String[] args) throws Exception, TransformerFactoryConfigurationError
      {
      final TransformerFactory newInstance = TransformerFactory.newInstance();
      final Object monitor = new Object ();

      for (;
      {
      synchronized (monitor)
      {
      new Thread ()
      {
      public void run ()
      {
      try
      {
      synchronized (monitor)

      { Source xsl = new StreamSource ("prova.xsl"); Transformer transformer = newInstance.newTransformer(xsl); Source xml = new StreamSource ("prova.xml"); transformer.transform(xml, new StreamResult ("ouput.xml")); monitor.notify(); }

      }
      catch (Exception e)

      { e.printStackTrace(); System.exit(1); }

      }
      }.start();
      monitor.wait();
      Thread.yield();
      }

      }
      }
      }

      ---------------------------------------------------------------------

      Attachments

        1. XMLReaderManager.java
          6 kB
          Carlo Marchiori
        2. XMLReaderManager.java
          6 kB
          Carlo Marchiori
        3. src.zip
          1.0 kB
          Carlo Marchiori

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ygmarchi Carlo Marchiori
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: