Grails/Tomcat/MySQL 过时连接错误,即使使用 JNDI 时也是如此?
我有几个 Grails 1.3.3 应用程序在 Tomcat 6.0.18 上运行。我意识到使用默认 Grails 数据源时存在数据库连接过时问题(连接在一段时间不活动后被终止),因此我切换到 Tomcat 提供的 JNDI。
我部署的第一个应用程序从未出现过任何过时的数据库连接问题。现在,我将第二个应用程序部署到具有相同 JNDI 数据源配置的同一服务器上,虽然第一个应用程序继续正常工作,但第二个应用程序在大约 8 个小时左右不活动后出现连接超时错误。 (出现错误后,连接会刷新并且再次正常工作)
数据源在 Tomcat 的 context.xml 中定义如下:
<Resource name="jdbc/firstDs" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="user1" password="password1" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/firstApp" />
<Resource name="jdbc/secondDs" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="user2" password="password2" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/secondApp" />
两个应用程序都使用 Datasource.groovy 文件中的 JNDI 数据源,如下所示(一切都完全相同,除了 jndiName):
dataSource {
pooled = false
}
...
environments {
...
production {
dataSource {
dbCreate = "update"
jndiName = "java:comp/env/jdbc/firstApp"
}
}
}
我知道这两种情况之间的唯一区别是工作应用程序使用 MyISAM 表,而非工作应用程序使用 InnoDB 表。有人遇到过 InnoDB 和 Tomcat 连接池的问题吗?如果我找不到其他可以尝试的东西,我可能会尝试切换到 MyISAM。
I have a couple of Grails 1.3.3 application running on Tomcat 6.0.18. I'm aware of the database connection staleness issue when using the default Grails datasource (connection gets killed after a period of inactivity), so I switched to JNDI provided by Tomcat.
The first app I deployed has never had any stale database connection problems. Now I deployed a second app to the same server with the same JNDI datasource configuration, and while the first continues to work fine, the second app gets the connection timeout error after about 8 or so hours of inactivity. (After the error the connection gets refreshed and it works just fine again)
The datasources are defined in Tomcat's context.xml as follows:
<Resource name="jdbc/firstDs" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="user1" password="password1" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/firstApp" />
<Resource name="jdbc/secondDs" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="user2" password="password2" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/secondApp" />
Both of the apps use the JNDI datasource in the Datasource.groovy file as follows (everything is exactly the same, except for the jndiName):
dataSource {
pooled = false
}
...
environments {
...
production {
dataSource {
dbCreate = "update"
jndiName = "java:comp/env/jdbc/firstApp"
}
}
}
The ONLY difference I'm aware of between these 2 situations is that working app uses MyISAM tables, while the non-working app uses InnoDB tables. Has anyone experienced an issue with InnoDB and Tomcat connection pooling? I may try switching to MyISAM if I can't find anything else to try.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 MySQL 和 Grails,最佳实践是在数据库池上进行验证查询。您可以附加到您的定义:
另请参阅 http:// tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources
For MySQL and Grails it's best practice to have a validation query on the db pool. You might append to your definitions:
See also http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources