Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 983723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:54:15+00:00 2026-05-16T04:54:15+00:00

I’d like to know which objects can be reused (in the same or different

  • 0
  1. I’d like to know which objects can be reused (in the same or different document) when using the Java API for XML processing, JAXP:

    • DocumentBuilderFactory
    • DocumentBuilder
    • XPath
    • Node
    • ErrorHandler (EDIT: I forgot that this has to be implemented in my own code, sorry)
  2. Is it recommended to cache those objects or do the JAXP implementations already cache them?

  3. Is the (re)use of those objects thread-safe?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:54:15+00:00Added an answer on May 16, 2026 at 4:54 am

    Reuse

    In the same thread those objects can and should be reused. For example you can use the DocumentBuilder to parse multiple documents.

    Thread Safety

    DocumentBuilderFactory used to explicity state it was not thread safe, I believe this is still true:

    An implementation of the
    DocumentBuilderFactory class is NOT
    guaranteed to be thread safe. It is up
    to the user application to make sure
    about the use of the
    DocumentBuilderFactory from more than
    one thread.

    • http://download.oracle.com/javase/1.4.2/docs/api/javax/xml/parsers/DocumentBuilderFactory.html

    From Stack Overflow, DocumentBuilder does not appear to be thread safe either. However in Java SE 5 a reset method was added to allow you to reuse DocumentBuilders:

    • Is DocumentBuilder.parse() thread safe?
    • http://download-llnw.oracle.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilder.html#reset()
    • http://www.junlu.com/msg/289939.html (about DocumentBuilder.reset())

    XPath is not thread safe, from the Javadoc

    An XPath object is not thread-safe and
    not reentrant. In other words, it is
    the application’s responsibility to
    make sure that one XPath object is not
    used from more than one thread at any
    given time, and while the evaluate
    method is invoked, applications may
    not recursively call the evaluate
    method.

    • http://download-llnw.oracle.com/javase/6/docs/api/javax/xml/xpath/XPath.html

    Node is not thread safe, from Xerces website

    Is Xerces DOM implementation
    thread-safe? No. DOM does not
    require implementations to be thread
    safe. If you need to access the DOM
    from multiple threads, you are
    required to add the appropriate locks
    to your application code.

    • http://xerces.apache.org/xerces2-j/faq-dom.html#faq-1

    ErrorHandler is an interface, so it is up to your implementation of that interface to ensure thread-safety. For pointers on thread-safety you could start here:

    • http://en.wikipedia.org/wiki/Thread_safety
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.