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

  • SEARCH
  • Home
  • 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 7192355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:55:22+00:00 2026-05-28T19:55:22+00:00

Is javax.xml.XPathFactory.newInstance() thread-safe? I’m asking because I find the documentation ambiguous for it. The

  • 0

Is javax.xml.XPathFactory.newInstance() thread-safe?

I’m asking because I find the documentation ambiguous for it. The JDK 5 docs don’t mention thread-safety at all; in JDK 6 they wrote the following:

The XPathFactory class is not thread-safe. In other words, it is the
application’s responsibility to ensure that at most one thread is
using a XPathFactory object at any given moment. Implementations are
encouraged to mark methods as synchronized to protect themselves from
broken clients.

As I understand it, it’s not safe to have a singleton implementation for XPathFactory, but doing something like this should be safe:

XPath xPathEvaluator = XPathFactory.newInstance().newXPath();

Am I missing something? Does it depend on the actual class that extends it? Do I need to synchronize the method that contains the above statement?

  • 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-28T19:55:23+00:00Added an answer on May 28, 2026 at 7:55 pm

    XPath xPathEvaluator = XPathFactory.newInstance().newXPath();

    That is safe, because every thread gets its own factory (thanks to newInstance()). No need to synchronize here.

    What you cannot safely do is get the factory just once, and then share it between threads without synchronization, for example as a singleton. The same goes for the XPath instance (xPathEvaluator) itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the standard Java 1.6 javax.xml.parsers.DocumentBuilder class thread safe? Is it safe to call
http://docs.oracle.com/javaee/6/api/javax/xml/rpc/soap/SOAPFaultException.html I am trying to import javax.xml.rpc.soap.SOAPFaultException More details in the Oracle's documentaiton. As
I am using javax.xml.validation.Validator from SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) to perform XSD validation. I would like to
According to the javadoc of javax.xml.validation.SchemaFactory#newInstance, I can specify which implementation of SchemaFactory I
http://download.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/XmlSeeAlso.html According to this, I should be able to make my root element have
I'm using the javax.xml.transform.Transformer class to perform some XSLT translations, like so: TransformerFactory factory
I wrote a handler (javax.xml.rpc.handler.Handler) for a SOAP web service that inspects header data.
I'm working with SOAP using the javax.xml.soap package. I have a javax.xml.soap.SOAPMessage object that
I am working on the following code: import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import
I need to include/inherit javax.xml.datatype.XmlGregorianCalendar in my GWT module. I have a proxy gxt.xml

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.