Skip to content

Commit 77c0318

Browse files
committed
优化随机id策略
1 parent 526dd72 commit 77c0318

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

hsweb-core/src/main/java/org/hswebframework/web/id/RandomIdGenerator.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import lombok.AllArgsConstructor;
66

77
import java.util.Base64;
8-
import java.util.HashSet;
9-
import java.util.Set;
108
import java.util.concurrent.ThreadLocalRandom;
119

1210
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@@ -17,6 +15,8 @@ public class RandomIdGenerator implements IDGenerator<String> {
1715
Integer.getInteger("generator.random.instance-id", ThreadLocalRandom.current().nextInt(1,127)).byteValue()
1816
);
1917

18+
static final Base64.Encoder encoder = Base64.getUrlEncoder().withoutPadding();
19+
2020
private final static FastThreadLocal<byte[]> HOLDER = new FastThreadLocal<byte[]>() {
2121
@Override
2222
protected byte[] initialValue() {
@@ -44,8 +44,7 @@ public String generate() {
4444
nextBytes(value, 6, 8);
4545
nextBytes(value, 8, 16);
4646
nextBytes(value, 16, 24);
47-
48-
return Base64.getUrlEncoder().encodeToString(value);
47+
return encoder.encodeToString(value);
4948
}
5049

5150

0 commit comments

Comments
 (0)