camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAMEL-803) ValidatingProcessor not thread-safe
Date Sat, 09 Aug 2008 12:02:52 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44884#action_44884
] 

Claus Ibsen commented on CAMEL-803:
-----------------------------------

I am wondering if the code below would do the trick?
I does however assume that it can create a new instance of the error handler provided.

{code:java}
        // create a new errorHandler and set it on the validator
        // must be a local instance to avoid problems with concurrency (to be thread safe)
        ValidatorErrorHandler handler = errorHandler.getClass().newInstance();
        validator.setErrorHandler(handler);

        DOMResult result = new DOMResult();
        validator.validate(source, result);

        handler.handleErrors(exchange, schema, result);
{code}

> ValidatingProcessor not thread-safe
> -----------------------------------
>
>                 Key: CAMEL-803
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-803
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 1.4.0
>            Reporter: Martin Krasser
>             Fix For: 1.5.0
>
>
> The method org.apache.camel.processor.validation.ValidatingProcessor.process() is executed
concurrently but error information is stored in a shared errorHandler. Because each thread
calls errorHandler.reset() it may clean errors written by another thread. The easiest way
to fix this issue would be a synchronized block:
> {code:java|title=ValidatingProcessor.java}
> ...
> synchronized (errorHandler) {
>     errorHandler.reset();
>     validator.setErrorHandler(errorHandler);
>     
>     DOMResult result = new DOMResult();
>     validator.validate(source, result);
>     
>     errorHandler.handleErrors(exchange, schema, result);
> }
> ... 
> {code}
> The disadvantage of this solution is that is serializes threads. A locally created error
handler would be preferrable ...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message