Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-12968

DefaultFluentProducerTemplate is not thread safe (endpoint, etc.)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.22.1, 2.23.0
    • 3.0.0.RC1, 3.0.0
    • camel-core
    • None
    • Unknown

    Description

      The DefaultFluentProducerTemplate saves state between method calls. This leads to unexpected behavior when the javadoc specifies that it should be thread safe.

      For example:

      1. thread 1 calls fluentProducerTemplate.to("direct:a").send("message1");
      2. thread 2 calls fluentProducerTemplate.to("direct:b").send("message2");

      If these are run in parallel, the sequence of calls can be:

      1. thread 1 calls to("direct:a") - endpoint in the object is direct:a
      2. thread 2 calls to("direct:b") - endpoint in the object is direct:b
      3. thread 1 calls send("message1") - this gets sent incorrectly to direct:b
      4. 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.

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            pdjohe Paul D Johe
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: