Concurrency problems with Templates and Transformer

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Concurrency problems with Templates and Transformer

Martynas Jusevičius
Hey,

since I've switched to Templates instead of Source to initialize
stylesheet in Java and started caching them, I'm sometimes
experiencing exceptions that I think are related to concurrency. For
example:

net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException;
Premature end of file.
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418)
at net.sf.saxon.event.Sender.send(Sender.java:214)
at net.sf.saxon.event.Sender.send(Sender.java:50)
at net.sf.saxon.Controller.transform(Controller.java:1611)
at org.graphity.client.util.XSLTBuilder.transform(XSLTBuilder.java:228)
at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:110)
at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:62)
Error
  SXXP0003: Error reported by XML parser: Premature end of file.

Also seems to be related, and crashes servlet container:

java.lang.NullPointerException
com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:134)
sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
java.io.BufferedWriter.flush(BufferedWriter.java:253)
net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:261)
net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:507)
net.sf.saxon.Controller.transformDocument(Controller.java:1848)
net.sf.saxon.Controller.transform(Controller.java:1621)

Can you give me some idea of what's going on and where? Should I
synchronize some of my code?

This is how I'm initializing Templates:

        Templates stylesheet = factory.newTemplates(stylesheet);
        handler = factory.newTransformerHandler(stylesheet);
        transformer = handler.getTransformer();

Templates, TransformerHandler and Transformer objects are shared
between requests, possibly concurrently. And this is how I transform
to a Result:

        Source document = new StreamSource(inputStream);
        Result result = new StreamResult(outputStream);
        handler.setResult(result);
        transformer.transform(document, result);

Any help is appreciated.

Martynas

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Concurrency problems with Templates and Transformer

Michael Kay
The Templates object is thread-safe, the Transformer object is not. From the Javadoc for Transformer:

An object of this class may not be used in multiple threads running concurrently. Different Transformers may be used concurrently by different threads.

For Saxon, I recommend creating a new Transformer for each transformation. It's serially reusable within a single thread, but it's usually more efficient to create a new one each time.

Michael Kay
Saxonica
[hidden email]
+44 (0) 118 946 5893




On 6 Feb 2015, at 18:16, Martynas Jusevičius <[hidden email]> wrote:

> Hey,
>
> since I've switched to Templates instead of Source to initialize
> stylesheet in Java and started caching them, I'm sometimes
> experiencing exceptions that I think are related to concurrency. For
> example:
>
> net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException;
> Premature end of file.
> at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418)
> at net.sf.saxon.event.Sender.send(Sender.java:214)
> at net.sf.saxon.event.Sender.send(Sender.java:50)
> at net.sf.saxon.Controller.transform(Controller.java:1611)
> at org.graphity.client.util.XSLTBuilder.transform(XSLTBuilder.java:228)
> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:110)
> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:62)
> Error
>  SXXP0003: Error reported by XML parser: Premature end of file.
>
> Also seems to be related, and crashes servlet container:
>
> java.lang.NullPointerException
> com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:134)
> sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
> sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
> sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
> java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
> java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
> java.io.BufferedWriter.flush(BufferedWriter.java:253)
> net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:261)
> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
> net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:507)
> net.sf.saxon.Controller.transformDocument(Controller.java:1848)
> net.sf.saxon.Controller.transform(Controller.java:1621)
>
> Can you give me some idea of what's going on and where? Should I
> synchronize some of my code?
>
> This is how I'm initializing Templates:
>
>        Templates stylesheet = factory.newTemplates(stylesheet);
>        handler = factory.newTransformerHandler(stylesheet);
>        transformer = handler.getTransformer();
>
> Templates, TransformerHandler and Transformer objects are shared
> between requests, possibly concurrently. And this is how I transform
> to a Result:
>
>        Source document = new StreamSource(inputStream);
>        Result result = new StreamResult(outputStream);
>        handler.setResult(result);
>        transformer.transform(document, result);
>
> Any help is appreciated.
>
> Martynas
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Concurrency problems with Templates and Transformer

Martynas Jusevičius
Thanks Michael.

So if I'm getting Transformer from
TransformerHandler.getTransformer(), I also need to create a new
TransformerHandler for each transformation?

On Fri, Feb 6, 2015 at 7:27 PM, Michael Kay <[hidden email]> wrote:

> The Templates object is thread-safe, the Transformer object is not. From the Javadoc for Transformer:
>
> An object of this class may not be used in multiple threads running concurrently. Different Transformers may be used concurrently by different threads.
>
> For Saxon, I recommend creating a new Transformer for each transformation. It's serially reusable within a single thread, but it's usually more efficient to create a new one each time.
>
> Michael Kay
> Saxonica
> [hidden email]
> +44 (0) 118 946 5893
>
>
>
>
> On 6 Feb 2015, at 18:16, Martynas Jusevičius <[hidden email]> wrote:
>
>> Hey,
>>
>> since I've switched to Templates instead of Source to initialize
>> stylesheet in Java and started caching them, I'm sometimes
>> experiencing exceptions that I think are related to concurrency. For
>> example:
>>
>> net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException;
>> Premature end of file.
>> at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418)
>> at net.sf.saxon.event.Sender.send(Sender.java:214)
>> at net.sf.saxon.event.Sender.send(Sender.java:50)
>> at net.sf.saxon.Controller.transform(Controller.java:1611)
>> at org.graphity.client.util.XSLTBuilder.transform(XSLTBuilder.java:228)
>> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:110)
>> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:62)
>> Error
>>  SXXP0003: Error reported by XML parser: Premature end of file.
>>
>> Also seems to be related, and crashes servlet container:
>>
>> java.lang.NullPointerException
>> com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:134)
>> sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
>> sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
>> sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
>> java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
>> java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
>> java.io.BufferedWriter.flush(BufferedWriter.java:253)
>> net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:261)
>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>> net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:507)
>> net.sf.saxon.Controller.transformDocument(Controller.java:1848)
>> net.sf.saxon.Controller.transform(Controller.java:1621)
>>
>> Can you give me some idea of what's going on and where? Should I
>> synchronize some of my code?
>>
>> This is how I'm initializing Templates:
>>
>>        Templates stylesheet = factory.newTemplates(stylesheet);
>>        handler = factory.newTransformerHandler(stylesheet);
>>        transformer = handler.getTransformer();
>>
>> Templates, TransformerHandler and Transformer objects are shared
>> between requests, possibly concurrently. And this is how I transform
>> to a Result:
>>
>>        Source document = new StreamSource(inputStream);
>>        Result result = new StreamResult(outputStream);
>>        handler.setResult(result);
>>        transformer.transform(document, result);
>>
>> Any help is appreciated.
>>
>> Martynas
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming. The Go Parallel Website,
>> sponsored by Intel and developed in partnership with Slashdot Media, is your
>> hub for all things parallel software development, from weekly thought
>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>> look and join the conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Concurrency problems with Templates and Transformer

Michael Kay
Yes, absolutely.

(The TransformerHandler is a ContentHandler that receives events from the SAX parser. If you run the same TransformerHandler in multiple threads, it will receive events from multiple parsers, all jumbled up together. There's no way that could possibly work!)

Michael Kay
Saxonica
[hidden email]
+44 (0) 118 946 5893




On 7 Feb 2015, at 16:18, Martynas Jusevičius <[hidden email]> wrote:

> Thanks Michael.
>
> So if I'm getting Transformer from
> TransformerHandler.getTransformer(), I also need to create a new
> TransformerHandler for each transformation?
>
> On Fri, Feb 6, 2015 at 7:27 PM, Michael Kay <[hidden email]> wrote:
>> The Templates object is thread-safe, the Transformer object is not. From the Javadoc for Transformer:
>>
>> An object of this class may not be used in multiple threads running concurrently. Different Transformers may be used concurrently by different threads.
>>
>> For Saxon, I recommend creating a new Transformer for each transformation. It's serially reusable within a single thread, but it's usually more efficient to create a new one each time.
>>
>> Michael Kay
>> Saxonica
>> [hidden email]
>> +44 (0) 118 946 5893
>>
>>
>>
>>
>> On 6 Feb 2015, at 18:16, Martynas Jusevičius <[hidden email]> wrote:
>>
>>> Hey,
>>>
>>> since I've switched to Templates instead of Source to initialize
>>> stylesheet in Java and started caching them, I'm sometimes
>>> experiencing exceptions that I think are related to concurrency. For
>>> example:
>>>
>>> net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException;
>>> Premature end of file.
>>> at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418)
>>> at net.sf.saxon.event.Sender.send(Sender.java:214)
>>> at net.sf.saxon.event.Sender.send(Sender.java:50)
>>> at net.sf.saxon.Controller.transform(Controller.java:1611)
>>> at org.graphity.client.util.XSLTBuilder.transform(XSLTBuilder.java:228)
>>> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:110)
>>> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:62)
>>> Error
>>> SXXP0003: Error reported by XML parser: Premature end of file.
>>>
>>> Also seems to be related, and crashes servlet container:
>>>
>>> java.lang.NullPointerException
>>> com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:134)
>>> sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
>>> sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
>>> sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
>>> java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
>>> java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
>>> java.io.BufferedWriter.flush(BufferedWriter.java:253)
>>> net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:261)
>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>> net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:507)
>>> net.sf.saxon.Controller.transformDocument(Controller.java:1848)
>>> net.sf.saxon.Controller.transform(Controller.java:1621)
>>>
>>> Can you give me some idea of what's going on and where? Should I
>>> synchronize some of my code?
>>>
>>> This is how I'm initializing Templates:
>>>
>>>       Templates stylesheet = factory.newTemplates(stylesheet);
>>>       handler = factory.newTransformerHandler(stylesheet);
>>>       transformer = handler.getTransformer();
>>>
>>> Templates, TransformerHandler and Transformer objects are shared
>>> between requests, possibly concurrently. And this is how I transform
>>> to a Result:
>>>
>>>       Source document = new StreamSource(inputStream);
>>>       Result result = new StreamResult(outputStream);
>>>       handler.setResult(result);
>>>       transformer.transform(document, result);
>>>
>>> Any help is appreciated.
>>>
>>> Martynas
>>>
>>> ------------------------------------------------------------------------------
>>> Dive into the World of Parallel Programming. The Go Parallel Website,
>>> sponsored by Intel and developed in partnership with Slashdot Media, is your
>>> hub for all things parallel software development, from weekly thought
>>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>>> look and join the conversation now. http://goparallel.sourceforge.net/
>>> _______________________________________________
>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming. The Go Parallel Website,
>> sponsored by Intel and developed in partnership with Slashdot Media, is your
>> hub for all things parallel software development, from weekly thought
>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>> look and join the conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Concurrency problems with Templates and Transformer

Martynas Jusevičius
Right. One last thing -- if the only methods I call are newTemplates()
and newTransformerHandler(), is there a difference if I use
TransformerFactory.newInstance() or
(SAXTransformerFactory)TransformerFactory.newInstance()? When is it
important to use the SAX factory subclass?

On Sat, Feb 7, 2015 at 8:26 PM, Michael Kay <[hidden email]> wrote:

> Yes, absolutely.
>
> (The TransformerHandler is a ContentHandler that receives events from the SAX parser. If you run the same TransformerHandler in multiple threads, it will receive events from multiple parsers, all jumbled up together. There's no way that could possibly work!)
>
> Michael Kay
> Saxonica
> [hidden email]
> +44 (0) 118 946 5893
>
>
>
>
> On 7 Feb 2015, at 16:18, Martynas Jusevičius <[hidden email]> wrote:
>
>> Thanks Michael.
>>
>> So if I'm getting Transformer from
>> TransformerHandler.getTransformer(), I also need to create a new
>> TransformerHandler for each transformation?
>>
>> On Fri, Feb 6, 2015 at 7:27 PM, Michael Kay <[hidden email]> wrote:
>>> The Templates object is thread-safe, the Transformer object is not. From the Javadoc for Transformer:
>>>
>>> An object of this class may not be used in multiple threads running concurrently. Different Transformers may be used concurrently by different threads.
>>>
>>> For Saxon, I recommend creating a new Transformer for each transformation. It's serially reusable within a single thread, but it's usually more efficient to create a new one each time.
>>>
>>> Michael Kay
>>> Saxonica
>>> [hidden email]
>>> +44 (0) 118 946 5893
>>>
>>>
>>>
>>>
>>> On 6 Feb 2015, at 18:16, Martynas Jusevičius <[hidden email]> wrote:
>>>
>>>> Hey,
>>>>
>>>> since I've switched to Templates instead of Source to initialize
>>>> stylesheet in Java and started caching them, I'm sometimes
>>>> experiencing exceptions that I think are related to concurrency. For
>>>> example:
>>>>
>>>> net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException;
>>>> Premature end of file.
>>>> at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418)
>>>> at net.sf.saxon.event.Sender.send(Sender.java:214)
>>>> at net.sf.saxon.event.Sender.send(Sender.java:50)
>>>> at net.sf.saxon.Controller.transform(Controller.java:1611)
>>>> at org.graphity.client.util.XSLTBuilder.transform(XSLTBuilder.java:228)
>>>> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:110)
>>>> at org.graphity.client.writer.ModelXSLTWriter.writeTo(ModelXSLTWriter.java:62)
>>>> Error
>>>> SXXP0003: Error reported by XML parser: Premature end of file.
>>>>
>>>> Also seems to be related, and crashes servlet container:
>>>>
>>>> java.lang.NullPointerException
>>>> com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:134)
>>>> sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
>>>> sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
>>>> sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
>>>> java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
>>>> java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
>>>> java.io.BufferedWriter.flush(BufferedWriter.java:253)
>>>> net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:261)
>>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>>> net.sf.saxon.event.ProxyReceiver.close(ProxyReceiver.java:90)
>>>> net.sf.saxon.event.ComplexContentOutputter.close(ComplexContentOutputter.java:507)
>>>> net.sf.saxon.Controller.transformDocument(Controller.java:1848)
>>>> net.sf.saxon.Controller.transform(Controller.java:1621)
>>>>
>>>> Can you give me some idea of what's going on and where? Should I
>>>> synchronize some of my code?
>>>>
>>>> This is how I'm initializing Templates:
>>>>
>>>>       Templates stylesheet = factory.newTemplates(stylesheet);
>>>>       handler = factory.newTransformerHandler(stylesheet);
>>>>       transformer = handler.getTransformer();
>>>>
>>>> Templates, TransformerHandler and Transformer objects are shared
>>>> between requests, possibly concurrently. And this is how I transform
>>>> to a Result:
>>>>
>>>>       Source document = new StreamSource(inputStream);
>>>>       Result result = new StreamResult(outputStream);
>>>>       handler.setResult(result);
>>>>       transformer.transform(document, result);
>>>>
>>>> Any help is appreciated.
>>>>
>>>> Martynas
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Dive into the World of Parallel Programming. The Go Parallel Website,
>>>> sponsored by Intel and developed in partnership with Slashdot Media, is your
>>>> hub for all things parallel software development, from weekly thought
>>>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>>>> look and join the conversation now. http://goparallel.sourceforge.net/
>>>> _______________________________________________
>>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Dive into the World of Parallel Programming. The Go Parallel Website,
>>> sponsored by Intel and developed in partnership with Slashdot Media, is your
>>> hub for all things parallel software development, from weekly thought
>>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>>> look and join the conversation now. http://goparallel.sourceforge.net/
>>> _______________________________________________
>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming. The Go Parallel Website,
>> sponsored by Intel and developed in partnership with Slashdot Media, is your
>> hub for all things parallel software development, from weekly thought
>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>> look and join the conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: Concurrency problems with Templates and Transformer

Michael Kay

> Right. One last thing -- if the only methods I call are newTemplates()
> and newTransformerHandler(), is there a difference if I use
> TransformerFactory.newInstance() or
> (SAXTransformerFactory)TransformerFactory.newInstance()? When is it
> important to use the SAX factory subclass?

You're calling the same method in both cases. Just in one case, you are causing your program to fail if the factory that's returned is not a SAXTransformerFactory. You need to do the cast if you want to invoke methods only available on a SAXTransformerFactory, such as newTransformerHandler().

Michael Kay
Saxonica



------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help