Skip to content

Commit f7dbf99

Browse files
committed
Caching XPathFactory to improve performance of exception handling for services using xml protocol
1 parent 3a82de3 commit f7dbf99

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"type": "feature",
4+
"description": "Caching `XPathFactory` to improve performance of exception handling for services using XML protocol"
5+
}

core/src/main/java/software/amazon/awssdk/core/util/XpathUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public final class XpathUtils {
6565

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

68+
/**
69+
* Shared factory for creating XML Factory
70+
*/
71+
private static final ThreadLocal<XPathFactory> X_PATH_FACTORY = ThreadLocal.withInitial(XPathFactory::newInstance);
72+
6873
private static final ErrorHandler ERROR_HANDLER = new ErrorHandler() {
6974

7075
@Override
@@ -156,7 +161,7 @@ private static void speedUpDcoumentBuilderFactory() {
156161
* reentrant.
157162
*/
158163
public static XPath xpath() {
159-
return XPathFactory.newInstance().newXPath();
164+
return X_PATH_FACTORY.get().newXPath();
160165
}
161166

162167
/**

0 commit comments

Comments
 (0)