mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1000651 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0ff144f7f4
commit
54bce47a81
|
@ -18,6 +18,7 @@ package org.apache.activemq.util;
|
|||
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -33,7 +34,8 @@ public class IdGenerator {
|
|||
private static int instanceCount;
|
||||
private static String hostName;
|
||||
private String seed;
|
||||
private long sequence;
|
||||
private AtomicLong sequence = new AtomicLong(1);
|
||||
private int length;
|
||||
|
||||
static {
|
||||
String stub = "";
|
||||
|
@ -70,6 +72,7 @@ public class IdGenerator {
|
|||
public IdGenerator(String prefix) {
|
||||
synchronized (UNIQUE_STUB) {
|
||||
this.seed = prefix + UNIQUE_STUB + (instanceCount++) + ":";
|
||||
this.length = this.seed.length() + ("" + Long.MAX_VALUE).length();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +99,10 @@ public class IdGenerator {
|
|||
*/
|
||||
|
||||
public synchronized String generateId() {
|
||||
return this.seed + (this.sequence++);
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
sb.append(seed);
|
||||
sb.append(sequence.getAndIncrement());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue