关于Linux或者Solaris下的随机数读取报错问题【/dev/[u]random closed?】

【问题现象】
Apusic启动正常,但是访问web控制台时提示如下错误:
2011-03-17 20:14:32 错误 [apusic.web.default./] 执行Servlet时发生错误。
java.security.ProviderException: nextBytes() failed
at sun.security.provider.NativePRNG$RandomIO.implNextBytes(NativePRNG.java:287)
at sun.security.provider.NativePRNG$RandomIO.access$200(NativePRNG.java:125)
at sun.security.provider.NativePRNG.engineNextBytes(NativePRNG.java:114)
at java.security.SecureRandom.nextBytes(SecureRandom.java:450)
at java.util.UUID.randomUUID(UUID.java:178)
at com.apusic.web.jsp.parser.TreeMaker.assignId(Unknown Source)
at com.apusic.web.jsp.parser.TreeMaker.processTag(Unknown Source)
at com.apusic.web.jsp.parser.JspPageParser.parseTag(Unknown Source)
at com.apusic.web.jsp.parser.JspPageParser.parse(Unknown Source)
at com.apusic.web.jsp.parser.JspPageParser.parse(Unknown Source)
at com.apusic.web.jsp.parser.JspParser.parse(Unknown Source)
at com.apusic.web.jsp.generator.JspCompilationContext.compile(Unknown Source)
at com.apusic.web.jsp.JspServlet$Page.load(Unknown Source)
at com.apusic.web.jsp.JspServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at com.apusic.web.container.ServletComponent.service(Unknown Source)
at com.apusic.web.container.WebContainer.invoke(Unknown Source)
at com.apusic.web.container.RequestDispatcherImpl.forward(Unknown Source)
at com.apusic.web.servlet.FileServlet.getResource(Unknown Source)
at com.apusic.web.servlet.FileServlet.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at com.apusic.web.container.ServletComponent.service(Unknown Source)
at com.apusic.web.container.WebContainer.invoke(Unknown Source)
at com.apusic.web.container.WebContainer.processRequest(Unknown Source)
at com.apusic.web.http.VirtualHost.processRequest(Unknown Source)
at com.apusic.web.http.HttpServer.processRequest(Unknown Source)
at com.apusic.web.http.HttpConnectionHandler.service(Unknown Source)
at com.apusic.web.http.ConnectionHandler.processRequest(Unknown Source)
at com.apusic.web.http.ConnectionHandler.processConnection(Unknown Source)
at com.apusic.web.http.ConnectionHandler.run(Unknown Source)
at com.apusic.util.ThreadPoolImpl$WorkerThread.run(Unknown Source)
Caused by: java.io.EOFException: /dev/[u]random closed?
at sun.security.provider.NativePRNG$RandomIO.readFully(NativePRNG.java:204)
at sun.security.provider.NativePRNG$RandomIO.ensureBufferValid(NativePRNG.java:264)
at sun.security.provider.NativePRNG$RandomIO.implNextBytes(NativePRNG.java:278)
... 31 more
【问题分析】
经查阅相关资料并从sun的官网上获取相关信息得知,这可能是sun的一个bug。
【问题解决】
基于目前的情况,解决方式如下,在JVM的启动参数中指定使用的随机数设备,如下:
-Djava.security.egd=file:/dev/./urandom
注意:此处的文件路经中有个dot,而不是/dev/urandom这个格式。
PS:从JDK的源码看,提供的随机数设备的路径分别是:/dev/random和/dev/urandom,但是有时os
也会因为连接错误导致读取随机数设备失败,可以尝试重新删除随机数设备的连接再重新绑定一次,如下:
rm -rf *random
ln -s random
ln -s urandom
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值