[
https://issues.apache.org/jira/browse/CXF-2229?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12711686#action_12711686
]
Daniel Kulp commented on CXF-2229:
----------------------------------
Hmmm.... definitiely a good reason to use woodstox instead of the sun parser.
Woodstox is thread safe in this instance. I'll add a sync block or similar.
Creating a new factory is VERY expensive and not something you want to do for
each call.
> thread safe issue caused by XMLOutputFactoryImpl
> ------------------------------------------------
>
> Key: CXF-2229
> URL: https://issues.apache.org/jira/browse/CXF-2229
> Project: CXF
> Issue Type: Bug
> Components: WS-* Components
> Affects Versions: 2.1.3
> Reporter: leon wu
>
> Currently CXF calls StaxUtils.getXMLOutputFactory() to get the cached
> instance of XMLOutputFactoryImpl. But
> XMLOutputFactoryImpl.createXMLStreamWriter is not thread-safe. See below.
> javax.xml.stream.XMLStreamWriter
> createXMLStreamWriter(javax.xml.transform.stream.StreamResult sr, String
> encoding) throws javax.xml.stream.XMLStreamException {
> try{
> if(fReuseInstance && fStreamWriter != null &&
> fStreamWriter.canReuse() && !fPropertyChanged){
> fStreamWriter.reset();
> fStreamWriter.setOutput(sr, encoding);
> if(DEBUG)System.out.println("reusing instance, object id : " +
> fStreamWriter);
> return fStreamWriter;
> }
> return fStreamWriter = new XMLStreamWriterImpl(sr, encoding, new
> PropertyManager(fPropertyManager)); -- this is not thread safe, since the
> new instance is assigned to the field fStreamWriter first, then it is
> possible that different threads get the same XMLStreamWriterImpl when they
> call this method at the same time.
> }catch(java.io.IOException io){
> throw new XMLStreamException(io);
> }
> }
> The solution might be, StaxUtils.getXMLOutputFactory() method creates a new
> instance of XMLOutputFactory every time, don't cache it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.