You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2021/03/23 06:21:00 UTC

[jira] [Resolved] (CAMEL-16316) ProducerTemplate asyncSend is not thread safe

     [ https://issues.apache.org/jira/browse/CAMEL-16316?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen resolved CAMEL-16316.
---------------------------------
    Resolution: Fixed

Added note to javadoc about the thread-safety issue

> 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-core
>    Affects Versions: 3.1.0, 3.7.2
>            Reporter: Zoltán Nébli
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 3.10.0
>
>
> 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)