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

Claus Ibsen commented on CAMEL-16316:
-------------------------------------

Camel 3.1 is rather old, try with 3.7.3

> ProducerTemplate asyncSend is not thread safe
> ---------------------------------------------
>
>                 Key: CAMEL-16316
>                 URL: https://issues.apache.org/jira/browse/CAMEL-16316
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-base
>    Affects Versions: 3.1.0
>            Reporter: Zoltán Nébli
>            Priority: Major
>
> The
> {code:java}
> CompletableFuture<Exchange> asyncSend(String endpointUri, Processor 
> processor){code}
> method is not thread safe because the processor is passed as a lambda to the 
> executor service:
> {code:java}
> getExecutorService().submit(() -> 
> getProducerCache().asyncSendExchange(endpoint, pattern, processor,
>  resultProcessor, inExchange, exchangeFuture));{code}
> and therefore if the caller use the original Exchange reference in the 
> Processor, for example
> {code:java}
> request -> request.setBody(originalExchange.getIn().getBody(...)){code}
> the executorService thread will use a dirty Exchange body in cases where the 
> original executor thread runs faster.
> On the other hand this method is thread safe because the new Exchange object 
> can be populated from the original exchange:
> {code:java}
> CompletableFuture<Exchange> asyncSend(String endpointUri, Exchange 
> exchange){code}
> I think the solution would be processing the request with the passed 
> processor then submit the job to the executor service or clearly mention this 
> in the API doc. This behavior is currently not straightforward.
> Of course you can pass references with the 2. method also which will become 
> dirty but I think the clear intention here is sending a clean Exchange 
> asynchronously to an endpoint with either a Processor or an exact Exchange 
> object.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to