You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by solimo <ro...@budzko.eu> on 2013/08/22 10:56:02 UTC

Camel JAXB DataFormat is not thread safe

Hello!

Recently, I've encountered an issue (I suppose) connected with Camel's
DataFormat implementation - the JAXB one. Due to exhausting tests, which we
currently perform we've noticed that Camel's implementation uses JAXB's
instances correctly (context is thread safe but products of context are not)
except part of implementation which loads schema.

Let's go through simple example and assume declaration as follows:

<camel:unmarshal id="channelV2Unmarshal">
    <camel:jaxb prettyPrint="true" contextPath="my.nice.package.model"
schema="schema-resource"/>
</camel:unmarshal>

Provided that route with such declaration allows concurrent processing (form
example thread pool) camel *might* throw exceptions like
org.xml.sax.SAXException (FWK005 parse may not be called while parsing). As
probably most of us perfectly know, such exception might be seen when some
JAXB instances are shared across many threads. Due to the fact that camels
implementation of this DataFormat is correct for marshalling/unmarshalling,
then removing "schema" attribute will solve the problem. Why - because of
SCHEMA_FACTORY field owned by JaxbDataFormat. Note that it's assigned
statically and then used in createUnmarshaller/createMarshaller.
Implementation of those method will use non thread safe instance assigned in
SCHEMA_FACTORY to create new instances of marshaller or unmarshaller for
each thread.

I suppose, it should not work this way, because during heavy load schema
validation on Camel's JAXB DataFormat might blow routes :).

Robert Budźko



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JAXB-DataFormat-is-not-thread-safe-tp5737748.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JAXB DataFormat is not thread safe

Posted by Christian Müller <ch...@gmail.com>.
I will add some notes to the Camel JAXB WIKI page later today about the fix
and a potential workaround for previous versions.

Best,
Christian
Am 23.08.2013 08:41 schrieb "Hack Kampbjørn" <
camel.users@list.hack.kampbjorn.com>:

> A workaround is to use a SchemaFactory implementation that is thread safe.
> The one bundled in JDK is not but the one in Xerces is.
>
> On 2013-08-22, at 12:38, solimo <ro...@budzko.eu> wrote:
>
> > Oh, how could I miss CAMEL-6630. Thanks.
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Camel-JAXB-DataFormat-is-not-thread-safe-tp5737748p5737759.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: Camel JAXB DataFormat is not thread safe

Posted by solimo <ro...@budzko.eu>.
Because both are parsing and this part of process is statefull, so somehow
they are more like builders not factories ;).



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JAXB-DataFormat-is-not-thread-safe-tp5737748p5737883.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JAXB DataFormat is not thread safe

Posted by Christian Müller <ch...@gmail.com>.
It looks like the Xerces SchemaFactory is also NOT thread-safe [1].

[1]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/SchemaFactory.html

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Fri, Aug 23, 2013 at 8:40 AM, Hack Kampbjørn <
camel.users@list.hack.kampbjorn.com> wrote:

> A workaround is to use a SchemaFactory implementation that is thread safe.
> The one bundled in JDK is not but the one in Xerces is.
>
> On 2013-08-22, at 12:38, solimo <ro...@budzko.eu> wrote:
>
> > Oh, how could I miss CAMEL-6630. Thanks.
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Camel-JAXB-DataFormat-is-not-thread-safe-tp5737748p5737759.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: Camel JAXB DataFormat is not thread safe

Posted by Hack Kampbjørn <ca...@list.hack.kampbjorn.com>.
A workaround is to use a SchemaFactory implementation that is thread safe. The one bundled in JDK is not but the one in Xerces is.

On 2013-08-22, at 12:38, solimo <ro...@budzko.eu> wrote:

> Oh, how could I miss CAMEL-6630. Thanks.
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-JAXB-DataFormat-is-not-thread-safe-tp5737748p5737759.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Camel JAXB DataFormat is not thread safe

Posted by solimo <ro...@budzko.eu>.
Oh, how could I miss CAMEL-6630. Thanks.



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JAXB-DataFormat-is-not-thread-safe-tp5737748p5737759.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel JAXB DataFormat is not thread safe

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

This is fixed by CAMEL-6630

On Thu, Aug 22, 2013 at 10:56 AM, solimo <ro...@budzko.eu> wrote:
> Hello!
>
> Recently, I've encountered an issue (I suppose) connected with Camel's
> DataFormat implementation - the JAXB one. Due to exhausting tests, which we
> currently perform we've noticed that Camel's implementation uses JAXB's
> instances correctly (context is thread safe but products of context are not)
> except part of implementation which loads schema.
>
> Let's go through simple example and assume declaration as follows:
>
> <camel:unmarshal id="channelV2Unmarshal">
>     <camel:jaxb prettyPrint="true" contextPath="my.nice.package.model"
> schema="schema-resource"/>
> </camel:unmarshal>
>
> Provided that route with such declaration allows concurrent processing (form
> example thread pool) camel *might* throw exceptions like
> org.xml.sax.SAXException (FWK005 parse may not be called while parsing). As
> probably most of us perfectly know, such exception might be seen when some
> JAXB instances are shared across many threads. Due to the fact that camels
> implementation of this DataFormat is correct for marshalling/unmarshalling,
> then removing "schema" attribute will solve the problem. Why - because of
> SCHEMA_FACTORY field owned by JaxbDataFormat. Note that it's assigned
> statically and then used in createUnmarshaller/createMarshaller.
> Implementation of those method will use non thread safe instance assigned in
> SCHEMA_FACTORY to create new instances of marshaller or unmarshaller for
> each thread.
>
> I suppose, it should not work this way, because during heavy load schema
> validation on Camel's JAXB DataFormat might blow routes :).
>
> Robert Budźko
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-JAXB-DataFormat-is-not-thread-safe-tp5737748.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen