All,

In StAXOMBuilder and MTOMXMLStreamWriter (renamed from OMOutputImpl),
XML{Input|Output}Factory is created just once now.
It is great to reuse XMLInputFactory and XMLOutputFactory instance, I
think.
But I am not sure whether XMLInputFactory.createXMLStreamReader() and
XMLOutputFactory.createXMLStreamWiter() have thread safety or not.
It seems that JSR-173 StAX specification does not mention their thread
safety.
IMHO, strictly speaking, these factories can be broken if these methods are
called concurrently.
These methods can be enclosed by synchronized block, or a factory instance
pool or something can be made.
Any comments?


BTW,
The code, XMLOutputFactory.newInstance().createXMLStreamWriter(output),
still exists in,,,
org.apache.axiom.om.impl.llom.OMNodeImpl
org.apache.axiom.om.impl.dom.NodeImpl

The code, XMLInputFactory.newInstance().createXMLStreamReader(input), still
exists in,,,
org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderImpl
org.apache.axiom.om.xpath.DocumentNavigator

These factory instances seem created in every accesses.

Thanks in advance,
Toshiro TAKASE
IBM Research, Tokyo Research Laboratory, Internet Technology
notes ID: Toshiro Takase/Japan/[EMAIL PROTECTED], e-mail: [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote on 2006/04/02 21:31:47:

> Author: dims
> Date: Sun Apr  2 05:31:46 2006
> New Revision: 390816
>
> URL: http://svn.apache.org/viewcvs?rev=390816&view=rev
> Log:
> create XMLOutputFactory just once
>
> Modified:
>
>
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/OMOutputImpl.

> java
>
> Modified:
>
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/OMOutputImpl.

> java
> URL: http://svn.apache.
>
org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/OMOutputImpl.

> java?rev=390816&r1=390815&r2=390816&view=diff
>
==============================================================================

> ---
>
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/OMOutputImpl.

> java (original)
> +++
>
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/OMOutputImpl.

> java Sun Apr  2 05:31:46 2006
> @@ -38,6 +38,7 @@
>   * also looking at the OM tree whether it has any optimizable content.
>   */
>  public class OMOutputImpl {
> +    private static XMLOutputFactory outputFactory =
> XMLOutputFactory.newInstance();
>      private XMLStreamWriter xmlWriter;
>      private OutputStream outStream;
>      private LinkedList binaryNodeList = new LinkedList();
> @@ -65,14 +66,12 @@
>          if (format.getCharSetEncoding() == null) //Default encoding is
UTF-8
>              format.setCharSetEncoding(OMOutputFormat.
> DEFAULT_CHAR_SET_ENCODING);
>
> -        XMLOutputFactory factory = XMLOutputFactory.newInstance();
> -
>          if (format.isOptimized()) {
>              bufferedSOAPBody = new StringWriter();
> -            xmlWriter = factory.createXMLStreamWriter(bufferedSOAPBody);
> +            xmlWriter = outputFactory.
> createXMLStreamWriter(bufferedSOAPBody);
>          } else {
>              try {
> -                xmlWriter = factory.createXMLStreamWriter(new java.
> io.BufferedWriter(new OutputStreamWriter(outStream,
> +                xmlWriter = outputFactory.createXMLStreamWriter(new
> java.io.BufferedWriter(new OutputStreamWriter(outStream,
>                          format.getCharSetEncoding())));
>              } catch (UnsupportedEncodingException e) {
>                  throw new XMLStreamException(e);
>
>

Reply via email to