SecureRandom.getInstanceStrong() 导致线程阻塞

Random random = SecureRandom.getInstanceStrong() ; 导致线程阻塞

真是史前巨坑,上生产环境导致线程阻塞,靠打印日志一点点定位这行代码。

/**
* 随机生成16位字符串
* @return
*/
public static String getRandomStr() {
try {
    log.info("start  getRandomStr...");
    Random random = SecureRandom.getInstanceStrong();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < STR_COUNT; i++) {
	int number = random.nextInt(BASE_RANDOM.length());
	sb.append(BASE_RANDOM.charAt(number));
    }
    log.info("end  getRandomStr...");
    return sb.toString();
}catch (Exception e){
    log.error("随机生成字符串异常",e);
    throw new Exception(e.getMessage());
}
}

如无特殊要求,采用new SecureRandom()来替代SecureRandom.getInstanceStrong()即可;

你可能感兴趣的:(java,html,javascript)