Centos JDBC ConnectReset解决方案

9 篇文章 0 订阅
5 篇文章 0 订阅

I was recently struggling with this exact same problem. I opened a ticket with Oracle and this is what they told me.
java.security.SecureRandom is a standard API provided by sun. Among various methods offered by this class void
nextBytes(byte[])
is one. This method is used for generating random bytes. Oracle 11g JDBC drivers use this API to generate random number during
login. Users using Linux have been encountering SQLException(“Io exception: Connection
reset”).
The problem is two fold
1. The JVM tries to list all the files in the /tmp (or alternate tmp directory set by -Djava.io.tmpdir) when
SecureRandom.nextBytes(byte[]) is invoked. If the number of files is large the
method takes a long time
to respond and hence cause the server to timeout
2. The method void nextBytes(byte[]) uses /dev/random on Linux and on some machines which lack the random
number generating hardware the operation slows down to the extent of bringing the whole login process to
a halt. Ultimately the the user encounters SQLException(“Io exception:
Connection reset”)
Users upgrading to 11g can encounter this issue if the underlying OS is Linux which is running on a faulty hardware.
Cause
The cause of this has not yet been determined exactly. It could either be a problem in
your hardware or the fact
that for some reason the software cannot read from dev/random
Solution
Change the setup for your application, so you add the next parameter to the java command:
-Djava.security.egd=file:/dev/…/dev/urandom
We made this change in our java.security file and it has gotten rid of the error.

上面是网上解决方案的大体来源,下面是根据上面原因的解决方案

System.setProperty("java.security.egd", "file:///dev/urandom");  // the 3 '/' are important to make it an URL
或者
rm /dev/random
ln -s /dev/urandom /dev/random

通过上面两种方案我都没有解决问题,后来修改了一下hosts,问题意外解决了,编辑hosts文件

vi /etc/hosts
10.0.8.220 hostname

我觉得可能是我

rm /dev/random
ln -s /dev/urandom /dev/random

修改完之后没有重启tomcat的问题,hosts可能只是误判,假如实在解决不了,可以试试修改hosts
假如还是出现问题,可以多线程相关代码,一般这个问题的产生都是伴随着多线程连接池的使用,在程序里使用了多线程,可以为多线程增加连接池,并减小连接池的并发数来解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值