Skip to content

Commit

Permalink
#82 XpathFactory moved to ThreadLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiranda committed Aug 10, 2018
1 parent bf33d1c commit e4fa554
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/xembly/XpathDirective.java
Expand Up @@ -58,7 +58,13 @@ final class XpathDirective implements Directive {
/**
* XPath factory.
*/
private static final XPathFactory FACTORY = XPathFactory.newInstance();
private static final ThreadLocal<XPathFactory> FACTORY =
new ThreadLocal<XPathFactory>() {
@Override
protected XPathFactory initialValue() {
return XPathFactory.newInstance();
}
};

/**
* Pattern to match root-only XPath queries.
Expand Down Expand Up @@ -135,7 +141,7 @@ private static Collection<Node> rootOnly(final String root,
private static Collection<Node> traditional(final String query,
final Node dom, final Collection<Node> current)
throws ImpossibleModificationException {
final XPath xpath = XpathDirective.FACTORY.newXPath();
final XPath xpath = XpathDirective.FACTORY.get().newXPath();
final Collection<Node> targets = new HashSet<Node>(0);
for (final Node node : XpathDirective.roots(dom, current)) {
final NodeList list;
Expand Down

0 comments on commit e4fa554

Please sign in to comment.