mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-21 11:07:23 +08:00
修改随机数获取实现为ThreadLocalRandom,减少对象反复创建的开销,同时减少线程争用
This commit is contained in:
@@ -25,7 +25,7 @@ public class SaFoxUtil {
|
||||
/**
|
||||
* 可以减少线程争用的随机对象
|
||||
*/
|
||||
private static final ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();
|
||||
|
||||
private SaFoxUtil() {
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class SaFoxUtil {
|
||||
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < length; i++) {
|
||||
int number = random.nextInt(62);
|
||||
int number = RANDOM.nextInt(62);
|
||||
sb.append(str.charAt(number));
|
||||
}
|
||||
return sb.toString();
|
||||
@@ -98,7 +98,7 @@ public class SaFoxUtil {
|
||||
* @return 随机字符串
|
||||
*/
|
||||
public static String getMarking28() {
|
||||
return System.currentTimeMillis() + "" + random.nextInt(Integer.MAX_VALUE);
|
||||
return System.currentTimeMillis() + "" + RANDOM.nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user