|
@@ -14,7 +14,7 @@ public class RandomIdGenerator implements IDGenerator<String> {
|
|
|
|
|
|
// java -Dgenerator.random.instance-id=8
|
|
// java -Dgenerator.random.instance-id=8
|
|
static final RandomIdGenerator GLOBAL = new RandomIdGenerator(
|
|
static final RandomIdGenerator GLOBAL = new RandomIdGenerator(
|
|
- Integer.getInteger("generator.random.instance-id", ThreadLocalRandom.current().nextInt()).byteValue()
|
|
|
|
|
|
+ Integer.getInteger("generator.random.instance-id", ThreadLocalRandom.current().nextInt(1,127)).byteValue()
|
|
);
|
|
);
|
|
|
|
|
|
private final static FastThreadLocal<byte[]> HOLDER = new FastThreadLocal<byte[]>() {
|
|
private final static FastThreadLocal<byte[]> HOLDER = new FastThreadLocal<byte[]>() {
|
|
@@ -30,10 +30,6 @@ public class RandomIdGenerator implements IDGenerator<String> {
|
|
return new RandomIdGenerator(instanceId);
|
|
return new RandomIdGenerator(instanceId);
|
|
}
|
|
}
|
|
|
|
|
|
- public static String random() {
|
|
|
|
- return GLOBAL.generate();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public String generate() {
|
|
public String generate() {
|
|
long now = System.currentTimeMillis();
|
|
long now = System.currentTimeMillis();
|
|
byte[] value = HOLDER.get();
|
|
byte[] value = HOLDER.get();
|
|
@@ -66,17 +62,4 @@ public class RandomIdGenerator implements IDGenerator<String> {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- System.out.println(random());
|
|
|
|
- System.out.println(random().length());
|
|
|
|
- Set<String> distinct = new HashSet<>(100_0000);
|
|
|
|
-
|
|
|
|
- long time = System.currentTimeMillis();
|
|
|
|
- for (int i = 0; i < 100_0000; i++) {
|
|
|
|
- distinct.add(random());
|
|
|
|
- }
|
|
|
|
- System.out.println(distinct.size());
|
|
|
|
- System.out.println(System.currentTimeMillis() - time);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|