当前位置: 代码迷 >> Java Web开发 >> 高分悬赏一个棘手的mysql连接有关问题
  详细解决方案

高分悬赏一个棘手的mysql连接有关问题

热度:5212   发布时间:2013-02-25 21:15:17.0
高分悬赏一个棘手的mysql连接问题
近期后台日志频繁报这个异常错误,让人很恼火,不知什么原因,请高手朋友帮忙看看!
jdbc连接的数据。

 The driver was unable to create a connection due to an inability to establish the client portion of a socket.

This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. 

For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.

For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.

This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. 

For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.

For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
at sun.reflect.GeneratedConstructorAccessor17.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)

------解决方案--------------------------------------------------------
是不是用了连接池,限制了连接数?
但是连接用完没有销毁呢?
其实我不知道,猜的
------解决方案--------------------------------------------------------
日志已经提示的很清楚了,你按照错误日志上的做就可以了
------解决方案--------------------------------------------------------
看上去使用了连接池。应该是插入或查询的数量过多造成的。
------解决方案--------------------------------------------------------
可能是连接池出现问题,
------解决方案--------------------------------------------------------
日志连解决办法都告诉你了,需要去按他说的试试
------解决方案--------------------------------------------------------
探讨
是不是用了连接池,限制了连接数?
但是连接用完没有销毁呢?
其实我不知道,猜的

------解决方案--------------------------------------------------------
http://blog.sina.com.cn/s/blog_5349193d0100wmrq
------解决方案--------------------------------------------------------
原因与解决方法:

 

1.操作系统对半连接数的限制。

 

这个可以使用迅雷菜单中的工具进行修改,或者使用tcpz软件来修改,其他的如:XP优化工具也有这个功能。

 

2.经过以上的修改还是发生异常

 

这个从MySQL的官方帮助文档中,有如下:

 

当你在具有很多TCP/IP连接的Windows上运行MySQL服务器,并经常在客户端上遇到“无法连接到MySQL服务器”错误时,可能是因为Windows不允许足够的临时(短命)端口用于这类连接。

默认情况下,Windows允许用于使用5000个临时(短命)TCP端口。任何端口关闭后,它将在TIME_WAIT状态保持120秒。与重新初始化全新的连接相比,该状态允许以更低的开销重新使用连接。但是,在该时间逝去前,无法再次使用该端口。

对于小的可用TCP端口堆栈(5000),以及具有TIME_WAIT状态的大量在短时间内打开和关闭的 TCP端口,你很可能遇到端口耗尽问题。处理该问题的方法有两种:
  相关解决方案