1
0
mirror of synced 2025-12-22 00:48:00 +08:00

🎨 #3732 Add Quarkus/GraalVM Native Image support - Fix Random instance initialization issues

This commit is contained in:
Copilot
2025-11-02 16:30:13 +08:00
committed by GitHub
parent e9bc5d0109
commit bb573afcaf
7 changed files with 182 additions and 13 deletions

View File

@@ -33,6 +33,19 @@ public class SignUtils {
return genRandomStr(32);
}
private static volatile Random random;
private static Random getRandom() {
if (random == null) {
synchronized (SignUtils.class) {
if (random == null) {
random = new Random();
}
}
}
return random;
}
/**
* 生成随机字符串
*
@@ -41,10 +54,10 @@ public class SignUtils {
*/
public static String genRandomStr(int length) {
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
Random r = getRandom();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
int number = random.nextInt(base.length());
int number = r.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();