Tomcat 在一个月不活动后关闭连接 - 如何避免?
我有一个在 tomcat/BlazeDS 上运行的 Flex/Java/MySQL/Hibernate 应用程序,其活动量非常低,用户甚至可以几个月不访问它。
一个月不活动后,tomcat 和 mysql 之间的连接关闭,然后我需要重新启动 mysql 和 tomcat 服务器的问题,有没有办法避免这种情况并保持连接始终打开?
I have a Flex/Java/MySQL/Hibernate application running on tomcat/BlazeDS which have very LOW activity, the user can even not visit it for months.
The problem that after a month of inactivity the connections between tomcat and mysql are closed and then I need to restart both the mysql and tomcat servers, is there a way to avoid that and maintain the connection always open?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MySQL 一段时间后关闭不活动的连接。 Hibernate 在其默认配置下不会重新连接。使用此处的建议启用自动重新连接:
http://www.databasesandlife .com/automatic-reconnect-from-hibernate-to-mysql/
MySQL closes inactive connections after some time. Hibernate in its default configuration will not reconnect. Use the advice here to enable automatic reconnection:
http://www.databasesandlife.com/automatic-reconnect-from-hibernate-to-mysql/
我不知道你是否可以阻止连接关闭,而且我也不确定这是个好主意。 您可以设置并使用Tomcat 上的连接池 当您请求资源时,它会自动重新连接。如果您配置了一定的最小值,一些连接池还会对实时连接进行定期测试,以便查看数据库是否仍然响应。
I don't know if you could stop the connection from closing, and I'm not really sure its that good an idea either. You can set up and use a connection pool on Tomcat which would automagically reconnect when you request the resource. Some connection pools will also do periodic testing on the live connections, if you configure a certain minimum, in order to see that the database is still responsive as well.
为什么不在代码中检查连接是否已关闭,如果是,则重新打开它?
或者使用连接池,我认为这会自动为您处理。 c3p0、bonecp、proxool、dbcp
Why don't you just put a check in the code to see if the connection is closed, and if it is, re-open it?
Or use a connection pool, I think that this would be handled for you automatically. c3p0, bonecp, proxool, dbcp