Java随机数坑 Oracle Connection reset 让tomcat启动更快

问题背景:
①程序莫名其妙: Caused by: java.net.SocketException: Connection reset
②Tomcat 启动慢html

bug来源:
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6202721java

测试示例:
https://blog.csdn.net/simplemurrina/article/details/79479183
import java.security.SecureRandom;tomcat

public class JRand {dom

public static void main(String args[]) throws Exception {

System.out.println("Ok: " +SecureRandom.getInstance("SHA1PRNG").nextLong());
}
}ide

执行测试:
time java JRand
time java -Djava.security.egd=file:/dev/urandom JRand
time java -Djava.security.egd=file:/dev/./urandom JRand
测试

解决办法
1.在Tomcat环境中解决优化

能够经过配置JRE使用非阻塞的Entropy Source。.net

在catalina.sh中加入这么一行:-Djava.security.egd=file:/dev/./urandom 便可。code

加入后再启动Tomcat,整个启动耗时降低到Server startup in 6213 ms,大大下降了启动的时间。htm

2.在JVM环境中解决

先执行which javac命令检查jdk安装路径

/usr/local/java/jdk1.8.0_92/bin/javac

去到$JAVA_PATH/jre/lib/security/java.security这个文件,找到下面的内容:

securerandom.source=file:/dev/urandom

替换成

securerandom.source=file:/dev/./urandom

参考:
https://blog.csdn.net/weixin_41350766/article/details/80063016

https://www.cnblogs.com/pthwang/p/8949445.html

https://blog.csdn.net/simplemurrina/article/details/79479183

https://blog.csdn.net/renfufei/article/details/70878077 tomcat优化启动

相关文章
相关标签/搜索