title: Java XPathFactory thread-safety
body: <p>Is javax.xml.XPathFactory.newInstance() thread-safe?</p>
  
  <p>I'm asking because I find the documentation ambiguous for it. <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/xml/xpath/XPathFactory.html" rel="noreferrer">The JDK 5 docs</a> don't mention thread-safety at all; in <a href="http://docs.oracle.com/javase/6/docs/api/javax/xml/xpath/XPathFactory.html" rel="noreferrer">JDK 6</a> they wrote the following:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>As I understand it, it's not safe to have a singleton implementation for <code>XPathFactory</code>, but doing something like this should be safe:</p>
  
  <pre><code>XPath xPathEvaluator = XPathFactory.newInstance().newXPath();
  </code></pre>
  
  <p>Am I missing something? Does it depend on the actual class that extends it? Do I need to <code>synchronize</code> the method that contains the above statement? </p>