Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-2932

A little optimization to IdGenerator and a potential issue with the counter

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.4.1
    • 5.4.2
    • Broker
    • None

    Description

      At Apache Camel we have a copy of the ActiveMQ IdGenerator

      Camel generator is here
      https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java

      ActiveMQ generator is here
      https://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java

      During some work to introduce pluggable id generators in Camel I did look at the source a bit more.

      1) sequence counter
      The sequence counter is a long primitive which uses ++ to increment. Its actually not guaranteed to be an atomic operation across all JVMs and OSs.
      Solution: Use a AtomicLong

      2) Optimize generateUuid() method
      The generator method concat strings using +
      I did some testing on my laptop and by using StringBuilder I could get it to be slightly faster. And I computed the max size the generated id could be so the string builder has allocated the space on start.
      Solution: Use StringBuilder

      See the Camel source code for example.

      Attachments

        Activity

          People

            Unassigned Unassigned
            davsclaus Claus Ibsen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: