[
https://issues.apache.org/jira/browse/CAMEL-16316?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17297600#comment-17297600
]
Zoltán Nébli commented on CAMEL-16316:
--------------------------------------
there is no 3.7.3 version on maven central but there is 3.7.2 and the
implementation is very similar of the *asyncSendExchange* method:
{code:java}
CompletableFuture<Exchange> exchangeFuture = new CompletableFuture();
this.getExecutorService().submit(() -> {
return this.getProducerCache().asyncSendExchange(endpoint, pattern, processor,
resultProcessor, inExchange, exchangeFuture);
});
return exchangeFuture;{code}
the processor lambda is not evaluated until a thread from the executor
threadpool starts work on it.
> 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: Minor
>
> 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)