Visitar URL original
Avoid unnecessary DocumentBuilderFactory Creation · Issue #182 · xmlunit/xmlunit · GitHub
Skip to content

Avoid unnecessary DocumentBuilderFactory Creation #182

Closed

Description

@tutufool

In DOMDifferenceEngine, we have:

    private DocumentBuilderFactory documentBuilderFactory =
        DocumentBuilderFactoryConfigurer.Default.configure(DocumentBuilderFactory.newInstance());

While if I provide my own DBF to DiffBuilder, above creation will be useless anyway due to override.

Since DOMDifferenceEngine is only used by DiffBuilder, I think it could be package private, and a constructor with DBF could be provided. (let DiffBuilder inject a DBF to it, either new or provided by caller).

Pretty much like the way to handle WhitespaceNormalizedSource.

I raise this issue because I observed some of my threads during LnP are running at below stack:

lang.Thread.State: RUNNABLE
at java.net.URLStreamHandler.parseURL(URLStreamHandler.java:255)
at java.net.URL.(URL.java:640)
at java.net.URL.(URL.java:508)
at sun.misc.URLClassPath$Loader.findResource(URLClassPath.java:701)
at sun.misc.URLClassPath.findResource(URLClassPath.java:225)
at java.net.URLClassLoader$2.run(URLClassLoader.java:572)
at java.net.URLClassLoader$2.run(URLClassLoader.java:570)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:569)
at org.springframework.boot.loader.LaunchedURLClassLoader.findResource(LaunchedURLClassLoader.java:53)
at java.lang.ClassLoader.getResource(ClassLoader.java:1090)
at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:233)
at org.apache.xerces.parsers.SecuritySupport$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.xerces.parsers.SecuritySupport.getResourceAsStream(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.findJarServiceProvider(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
at org.apache.xerces.parsers.DOMParser.(Unknown Source)
at org.apache.xerces.parsers.DOMParser.(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setFeature(Unknown Source)

Which indicate DBF's creation is a heavy operation.
(I already have my own thread-local bases DBF passed into DiffBuilder)

Thanks in advance for looking into it.

Leon

Activity

  1. added this to the 2.7.0 milestone on May 11, 2020
  2. bodewig commented on May 11, 2020

    @bodewig
    Member

    DOMDifferenceEngine and DiffBuilder live in separate packages, so package private is not an option. To me the builder API has always been an alternative API to creating DOMDifferenceEngine directly so it has to stay public anyway.

    Back when I added setDocumentFactory I should have chosen a new constructor instead, I don't recall why I opted for the setter.

  3. bodewig commented on May 11, 2020

    @bodewig
    Member

    I've changed the code to use a separate constructor now.

  4. tutufool commented on May 12, 2020

    @tutufool
    Author

    Cool, thanks for the super fast fix

  5. bodewig commented on May 12, 2020

    @bodewig
    Member

    2.7.0 has just been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions