Java threads backed up in XPathContext initialization and DTMManager.newInstance

Solution Verified - Updated

Environment

  • JBoss Enterprise Application Platform (EAP)
    • 6
    • 7

Issue

  • Many java threads backed up in XPathContext initialization and resulting DTMManager.newInstance calls, for example:
   java.lang.Thread.State: BLOCKED (on object monitor)
	at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:676)
	- waiting to lock <0x00000000a1931868> (a java.util.jar.JarFile)
	at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:415)
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
	- locked <0x00000000ec1c7a88> (a java.io.InputStreamReader)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at java.io.BufferedReader.fill(BufferedReader.java:154)
	at java.io.BufferedReader.readLine(BufferedReader.java:317)
	- locked <0x00000000ec1c7a88> (a java.io.InputStreamReader)
	at java.io.BufferedReader.readLine(BufferedReader.java:382)
	at org.apache.xml.dtm.ObjectFactory.findJarServiceProviderName(ObjectFactory.java:588)
	at org.apache.xml.dtm.ObjectFactory.lookUpFactoryClassName(ObjectFactory.java:373)
	at org.apache.xml.dtm.ObjectFactory.lookUpFactoryClass(ObjectFactory.java:206)
	at org.apache.xml.dtm.ObjectFactory.createObject(ObjectFactory.java:131)
	at org.apache.xml.dtm.ObjectFactory.createObject(ObjectFactory.java:101)
	at org.apache.xml.dtm.DTMManager.newInstance(DTMManager.java:142)
	at org.apache.xpath.XPathContext.<init>(XPathContext.java:114)
	at org.apache.xpath.XPathContext.<init>(XPathContext.java:321)

or

 java.lang.Thread.State: BLOCKED (on object monitor)
	at java.util.zip.ZipFile.getEntry(ZipFile.java:314)
	- waiting to lock <0x000000041ca4a870> (a java.util.jar.JarFile)
	at java.util.jar.JarFile.getEntry(JarFile.java:240)
	at java.util.jar.JarFile.getJarEntry(JarFile.java:223)
	at org.jboss.modules.JarFileResourceLoader.getJarEntry(JarFileResourceLoader.java:185)
	at org.jboss.modules.JarFileResourceLoader.getResource(JarFileResourceLoader.java:217)
	at org.jboss.modules.ModuleClassLoader.loadResourceLocal(ModuleClassLoader.java:351)
	at org.jboss.modules.ModuleClassLoader$1.loadResourceLocal(ModuleClassLoader.java:103)
	at org.jboss.modules.Module.getResourceAsStream(Module.java:635)
	at org.jboss.modules.ModuleClassLoader.findResourceAsStream(ModuleClassLoader.java:587)
	at org.jboss.modules.ConcurrentClassLoader.getResourceAsStream(ConcurrentClassLoader.java:362)
	at org.apache.xml.dtm.SecuritySupport12$6.run(SecuritySupport12.java:121)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.apache.xml.dtm.SecuritySupport12.getResourceAsStream(SecuritySupport12.java:114)
	at org.apache.xml.dtm.ObjectFactory.findJarServiceProviderName(ObjectFactory.java:551)
	at org.apache.xml.dtm.ObjectFactory.lookUpFactoryClassName(ObjectFactory.java:375)
	at org.apache.xml.dtm.ObjectFactory.lookUpFactoryClass(ObjectFactory.java:208)
	at org.apache.xml.dtm.ObjectFactory.createObject(ObjectFactory.java:133)
	at org.apache.xml.dtm.ObjectFactory.createObject(ObjectFactory.java:103)
	at org.apache.xml.dtm.DTMManager.newInstance(DTMManager.java:137)
	at org.apache.xpath.XPathContext. (XPathContext.java:102)
	at org.apache.xpath.XPathAPI.eval(XPathAPI.java:225)
	at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:167)
	at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:147)
...

Resolution

  • If possible, change application code to cache and reuse the XPathContext instance, which is thread-safe, instead of constantly recreating it.
  • A more immediate fix would be to add -Dorg.apache.xml.dtm.DTMManager=org.apache.xml.dtm.ref.DTMManagerDefault or -Dcom.sun.org.apache.xml.internal.dtm.DTMManager= com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault to the java options, so it does not need to read the jar file contents on every call.

Root Cause

  • Content from issues.apache.org is not included.XALANJ-2540
  • If the DTMManager class name is not found from the system property set in JVM options or a $JAVA_HOME/jre/lib/xalan.propreties file, then a more expensive jar look up is performed to find the value each time DTMManager.newInstance is called
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.