Reputation: 9776
There is an example code here:
x = XPath.newInstance("//collection/dvd[@id='B']");
Element e = (Element)x.selectSingleNode(doc);
listElement(e, "");
The question in me is how can I make it fast if the code is often called. The documentation does not say anything about it (XPath API doc).
If you have experience with JDOM and XPath, let me know the answers please.
Upvotes: 0
Views: 1361
Reputation: 12817
Just for the record, the adapter that links JDOM to its default implementation, Jaxen, is not thread safe. This is easily concluded from a quick study of the org.jdom.xpath code.
As for the more general question about thread safety: If the documentation for an API doesn't explicitly claim to be thread safe, the assumption must always be that is not (and that is almost always the case, too). And it is always prudent to question the thread safety claim, as well.
Upvotes: 2
Reputation: 163418
It can be difficult to find documentation that answers such questions: for example, many people are surprised to find that DOM is not thread-safe. I believe that JDOM is, but I don't know about its XPath engine. If you use Saxon as your XPath engine (it works with JDOM), the s9api interface is expressly designed to allow a compiled expression to be created in one thread and used in multiple threads concurrently.
Upvotes: 1