[ https://issues.apache.org/jira/browse/CAMEL-12968?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16704814#comment-16704814 ]
Paul D Johe commented on CAMEL-12968: ------------------------------------- As far as I can see, 2.23.0 still has this code: {code:java} public class DefaultFluentProducerTemplate extends ServiceSupport implements FluentProducerTemplate { ... private Optional<Endpoint> endpoint; ... @Override public FluentProducerTemplate to(Endpoint endpoint) { this.endpoint = Optional.of(endpoint); return this; } ... @Override public Exchange send() throws CamelExecutionException { // Determine the target endpoint final Endpoint target = target(); return exchangeSupplier.isPresent() ? template().send(target, exchangeSupplier.get().get()) : template().send(target, processorSupplier.orElse(() -> defaultProcessor()).get()); } ... private Endpoint target() { if (endpoint.isPresent()) { return endpoint.get(); } if (defaultEndpoint.isPresent()) { return defaultEndpoint.get(); } throw new IllegalArgumentException("No endpoint configured on FluentProducerTemplate. You can configure an endpoint with to(uri)"); } }{code} Endpoint is not a thread local, and between to and send method calls, the endpoint state may have changed. > DefaultFluentProducerTemplate is not thread safe (endpoint, etc.) > ----------------------------------------------------------------- > > Key: CAMEL-12968 > URL: https://issues.apache.org/jira/browse/CAMEL-12968 > Project: Camel > Issue Type: Bug > Components: camel-core > Affects Versions: 2.22.1, 2.23.0 > Reporter: Paul D Johe > Priority: Major > > The DefaultFluentProducerTemplate saves state between method calls. This > leads to unexpected behavior when the javadoc specifies that it should be > thread safe. > For example: > # thread 1 calls fluentProducerTemplate.to("direct:a").send("message1"); > # thread 2 calls fluentProducerTemplate.to("direct:b").send("message2"); > If these are run in parallel, the sequence of calls can be: > # thread 1 calls to("direct:a") - endpoint in the object is direct:a > # thread 2 calls to("direct:b") - endpoint in the object is direct:b > # *thread 1 calls send("message1") - this gets sent incorrectly to direct:b* > # thread 2 calls send("message2") - this gets sent correctly to direct:b > Endpoint is one example, but almost all fields in this class share this > behavior. It should be clearly documented which fields can be used fluently > over multiple threads, and which cannot. As the API is today, all methods > returning 'this' should be made thread-safe (state is only local to the > caller) so that the fluent interface works as expected. -- This message was sent by Atlassian JIRA (v7.6.3#76005)