To determine if your operating system exhibits this behavior, try displaying a portion of the file from a shell prompt:
head -n 1 /dev/random
Open the $JAVA_HOME/jre/lib/security/java.security file in a text editor.
Change the line:
securerandom.source=file:/dev/random
to read:
securerandom.source=file:/dev/urandom
Save your change and exit the text editor.
其中说到:可通过 head -n 1 /devrandom 查看是否你的系统会出现伪随机数提供等待。OK就这个,试了一下,果然,在服务器第一次启动后,这个可以快速提供一个值,但当再次调用时发生等待。
解决办法:
永久:oracle 说修改 $JAVA_HOME/jre/lib/security/java.security 文件,替换securerandom.source=file:/dev/random 为 securerandom.source=file:/dev/urandom。对所有使用JVM的应用生效。(这个永久的方法,这里面有个问题,就是设置时候实际应该设置为securerandom.source=file:/dev/./urandom,否则不生效)
DOMAIN临时:修改startWeblogic.sh文件,JAVA_OPTIONS="${SAVE_JAVA_OPTIONS} -Djava.security.egd=file:/dev/./urandom"
后继的SecureRandom 测试学习
编写JAVA类如下,运行测试,第一次正常,第二次等待,重启服务器后第一次又正常。启动加入参数 -Djava.security.egd=file:/dev/./urandom 正常
java -Djava.security.egd=file:/dev/./urandom Test
源码如下:
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.Security;
public class Test {
public static void main(String[] args) {
try {
System.out.println("Begin to get SecureRandom Instance.");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
System.out.println("SR is ready for use....");
System.out.println("Next double is :" + sr.nextDouble());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
}
结束语:
唉,这些可能影响应用的东西应该在安装文档之前就应该执行的检查啊,希望甲骨文这个地方效仿IBM ,安装文档执行检查,安装包提供preInstallCheck脚本,以避免异常。