IT技术博客大学习 共学习 共进步

Java Crypto在Linux下性能低下问题的解决方案

Elton's Blog 2013-02-28 23:43:34 浏览 2,302 次

在Linux下,如果你使用 java.security 包中的方法(比如SecureKeyFactory.generateSecret()),会发现它出奇的慢,有时候甚至是半僵死在那里。

有两个方法解决这个问题

1. 编辑${java.home}/jre/lib/security/java.security,找到securerandom.source,把它的值改成(默认值file:/dev/urandom,效果很差)

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

2. 安装rng-tools

[root@linux ~]# yum install rng-tools

[root@linux ~]# echo 'EXTRAOPTIONS="-i -o /dev/random -r /dev/urandom -t 10 -W 2048"' > /etc/sysconfig/rngd

[root@linux ~]# chkconfig rngd on

[root@linux ~]# service rngd restart

参考:http://development.adaptris.com/~lchan/blog/2012/06/15/slow-java-crypto-performance-on-linux/