Browse Source
XMLReaderFactory has been marked as deprecated and without additional configuration, and it's slower than SAXParserFactory. Previously `XMLReaderFactory.createXMLReader()` is called upon every request. This is an anti-pattern as mentioned in [1] and it can be very slow since it loads the jar service file unless a parser has been pre-assigned [2] (e.g. by setting org.xml.sax.driver). SAXParserFactory uses a FactoryFinder [3] instead, which takes advantage of a thread-local cache provided by ServiceLoader. Developers can still pre-assign a factory by setting javax.xml.parsers.SAXParserFactory to make it faster. [1] https://bugs.openjdk.java.net/browse/JDK-6925410 [2]pull/27763/headc8add223a1/src/java.xml/share/classes/org/xml/sax/helpers/XMLReaderFactory.java (L144-L148)
[3]66c653c561/src/java.xml/share/classes/javax/xml/parsers/SAXParserFactory.java (L181-L185)
See gh-27239
Frederick Zhang
3 years ago
committed by
Stephane Nicoll
8 changed files with 71 additions and 34 deletions
Loading…
Reference in new issue