jdom icon indicating copy to clipboard operation
jdom copied to clipboard

Make TransformerFactory static

Open mstaal opened this issue 5 years ago • 2 comments

I have been taking a look at the class XSLTransformer.java: https://github.com/hunterhacker/jdom/blob/master/core/src/java/org/jdom2/transform/XSLTransformer.java

Why is it that on line 127 a new instance of TransformerFactory is made whenever a new XSLTransformer is instantiated? From what I have read, TransformerFactory is thread safe (so it might as well be made static), and it is (from what I have read) expensive in terms of performance to instantiate a new factory.

mstaal avatar Jul 09 '19 06:07 mstaal

Could be legacy reasons from before it was thread safe. Could be a strategic decision made by Rolf. Was a long long time ago. Not sure.

hunterhacker avatar Jul 17 '19 23:07 hunterhacker

This was not done intentionally, it's a transfer from 1.x version: https://github.com/hunterhacker/jdom/blob/jdom-1.1/core/src/java/org/jdom/transform/XSLTransformer.java#L133

This needs some consideration as to whether changing it now would pose a compatibility risk.

Is there a specific concern you have that would be improved by making it static? I can understand that if you have many stylesheets being used to construct transforms in a tight loop, that there may be a performance issue, but this seems like a stretch.

What's the particular concern?

rolfl avatar Jul 02 '21 02:07 rolfl