频繁连接断开mysql出现的问题

4 篇文章 0 订阅

今天写的程序需要频繁执行连接断开mysql这一操作,而且时间间隔又很短,于是乎出现了下面这个问题

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).  

意思是说本地的套接字缓存不够了,因此获取不到数据库的连接,可参考这篇文章:http://support2.microsoft.com/kb/196271。

为什么套接字会不够了?因为,我刚才提到了,执行sql操作的时间间隔很短,但是在默认情况下,windows允许使用5000个临时TCP端口,任何端口关闭后,它将在TIME_WAIT状态下保持120秒,所以理论上讲如果 时间间隔 < 120/5000 的话,就会出现套接字用光的问题。

我的解决方法是:

1.使用连接池

2.每次执行完一个操作后再执行下Thread.sleep(200) 即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值