连接按db删除

cclgggtu  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(286)

我有一个大约20个测试程序集的系统。这个系统建立数据库连接来获取一些数据。我使用hibernate和c3p0来管理我的连接和guice,以确保使用 @transactional 注解。大约有0.3%的请求由于数据库连接问题而失败。这就是堆栈跟踪的样子。

javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not prepare statement
.
.
.
Caused by: org.hibernate.exception.JDBCConnectionException: could not prepare statement
.
.
.
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed

.
.
.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
.
.
.
Caused by: java.net.SocketException: Connection reset

我的hibernate c3p0设置是:

hibernate.connection.url = "jdbc:mysql://dbHost.com:3306/DB";
  hibernate.dialect = "org.hibernate.dialect.MySQLDialect";
  hibernate.cache.provider_class = "org.hibernate.cache.NoCacheProvider";
  hibernate.hbm2ddl.auto = "update";
  hibernate.show_sql = "false";
  hibernate.connection.provider_class = "org.hibernate.c3p0.internal.C3P0ConnectionProvider";
  hibernate.c3p0.min_size = "100";
  hibernate.c3p0.max_size = "100";
  hibernate.c3p0.idle_test_period = "100";
  hibernate.c3p0.max_statements = "0";
  hibernate.c3p0.timeout = "86400";
  hibernate.c3p0.preferredTestQuery = "select 1";

my db系统变量:

connect_timeout=10
wait_timeout=86500
interactive_timeout=28800

这些错误是随机发生的,当对最初失败的同一个输入重试时,它就工作了。
我做错什么了?

l5tcr1uw

l5tcr1uw1#

可能是最简单的方法(希望如此!)这是要添加的地址。。。

hibernate.c3p0.testConnectionOnCheckout = "true"

用你的 preferredTestQuery 当然,这不太可能是性能问题。有关连接测试的一些建议,请参见此处。

相关问题