Skip to content

Caching XPathFactory #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-deb2963.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category": "AWS SDK for Java v2",
"type": "feature",
"description": "Caching `XPathFactory` to improve performance of exception handling for services using XML protocol"
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public final class XpathUtils {

private static final Logger log = LoggerFactory.getLogger(XpathUtils.class);

/**
* Shared factory for creating XML Factory
*/
private static final ThreadLocal<XPathFactory> X_PATH_FACTORY = ThreadLocal.withInitial(XPathFactory::newInstance);

private static final ErrorHandler ERROR_HANDLER = new ErrorHandler() {

@Override
Expand Down Expand Up @@ -156,7 +161,7 @@ private static void speedUpDcoumentBuilderFactory() {
* reentrant.
*/
public static XPath xpath() {
return XPathFactory.newInstance().newXPath();
return X_PATH_FACTORY.get().newXPath();
}

/**
Expand Down