1.场景问题
场景:项目启动阶段初始化数据库连接池
## Oracle数据库
## 服务端连接数1500
## 项目maxActive=20
## 服务端连接43
## 说明:启动一直报错,但是项目是可以启动起来的
2.分析问题
错误一:
## 连接ORACLE服务器,客户端要生成随机密钥用于客户端认证,JDK默认使用/dev/random,random采用阻塞方式生成随机数,生成的速度很慢,ORACLE服务器会主动reset,然后报错。
错误二:
## 其实差不多,是因为算法速度的问题导致的
3.解决方案
一:修改jdk目录下文件配置
> vim $JAVA_HOME/jre/lib/security/java.security
## 将securerandom.source=file:/dev/random 改为file:/dev/urandom(urandom采用非阴塞式生成随机数,性能很好,不会产生超时)
- 其实在查看发现默认的就是:file:/dev/urandom
- 认为可能没有使用此处的文件,或不是这么使用的
二:JVM参数方式
> vim 项目启动脚本.sh
> vim JAVA_OPTIONS = "-Djava.security.egd=file:/dev/./urandom"
4.JDK源码分析
if (egdSource.equals(URL_DEV_RANDOM) || egdSource.equals(URL_DEV_URANDOM)){
try {
instance = new NativeSeedGenerator();
if (debug != null) {
debug.println("the instance:"+instance.getClass());
debug.println("Using operating system seed generator");
}
} catch (IOException e) {
if (debug != null) {
debug.println("Failed to use operating system seed "
+ "generator: "+ e.toString());
}
}
}
else if (egdSource.length() != 0) {
try {
instance = new URLSeedGenerator(egdSource);
if (debug != null) {
debug.println("Using URL seed generator reading from "
+ egdSource);
}
} catch (IOException e) {
if (debug != null)
debug.println("Failed to create seed generator with "
+ egdSource + ": " + e.toString());
}
}
参考链接:https://blog.youkuaiyun.com/raintungli/article/details/42876073