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.