您的位置:首页 > 编程语言 > Java开发

java.net.SocketException异常的可能性分析

2010-04-09 11:32 288 查看
java.net.SocketException异常的可能性分析
近来在做一个MQ的项目,当部署完毕,运行后每隔两三天就会down机一次,软件死了。通过系统日志分析:
InforSuiteV6.0.0 Build2009042101 started
2010-3-29 15:58:36 ClientCommunicatorAdmin restart
警告: Failed to restart: java.io.IOException: Failed to get a RMI stub: javax.na
ming.CommunicationException [Root exception is java.rmi.ConnectIOException: Exce
ption creating connection to: 127.0.0.1; nested exception is:
        java.net.SocketException: No buffer space available (maximum connections
 reached?): JVM_Bind]
2010-3-29 15:58:36 RMIConnector RMIClientCommunicatorAdmin-doStop
警告: Failed to call the method close():java.rmi.ConnectIOException: Exception c
reating connection to: 10.0.0.2; nested exception is:
        java.net.SocketException: No buffer space available (maximum connections
 reached?): JVM_Bind
2010-3-29 15:58:36 ClientCommunicatorAdmin Checker-run
警告: Failed to check connection: java.net.SocketException: No buffer space avai
lable (maximum connections reached?): JVM_Bind
2010-3-29 15:58:36 ClientCommunicatorAdmin Checker-run
警告: stopping
2010-3-29 15:58:52 ClientCommunicatorAdmin restart
警告: Failed to restart: java.io.IOException: Failed to get a RMI stub: javax.na
ming.CommunicationException [Root exception is java.rmi.ConnectIOException: Exce
ption creating connection to: 127.0.0.1; nested exception is:
        java.net.SocketException: No buffer space available (maximum connections
 reached?): JVM_Bind]
发现抛出了一些Socket异常,这些异常均是由文件句柄使用完毕而引起的。也就是说程序里面打开的socket,没有及时关闭掉。为了进一步寻求技术支持,确认分析是否合理,寻找sun的网站资料:
Chances are you are forgetting to close a socket, a database connection, or some other connection that uses sockets internally. See example program below.
The alternative is that your program (or the sum of all programs running on your computer) really needs a lot of connections. In this case you'll need to find out how to increase the amount of socket buffer space that your operating system allocates. I'd start by googling for instructions. Or maybe you could redesign your program so that it doesn't use so much resources.
Sun的技术支持确认了之前分析的有理。java.net.SocketException异常与socket没有关闭有关,操作系统有它允许持有的最大文件句柄数,而在网络连接的过程中,每个socket请求都要占用一个文件句柄资源,如果没有及时释放,则可能会耗尽文件句柄资源.
 
所以,及时关闭那些不再使用的socket,能够合理的解决抛出的java.net.SocketException异常。
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐