我遇到以下错误,我很难调试此问题的来源。我有以下两个会议工厂:
<bean id="sessionFactory1"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.driver_class">${db.driver}</prop>
<prop key="hibernate.connection.url">${db.jdbcurl2}</prop>
<prop key="hibernate.connection.username">${db.username2}</prop>
<prop key="hibernate.connection.password">${db.password2}</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider
</prop>
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.max_size">6</prop>
<prop key="hibernate.c3p0.maxIdleTime">3000</prop>
<prop key="hibernate.c3p0.timeout">5000</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.idle_test_period">3000</prop>
<prop key="hibernate.c3p0.preferredTestQuery">SELECT 1</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql" >false</prop>
<prop key="hibernate.format_sql" >false</prop>
<prop key="hibernate.hbm2ddl.auto" >update</prop>
</props>
</property>
</bean>
<bean id="sessionFactory2"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" primary="true">
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.driver_class">${db.driver}</prop>
<prop key="hibernate.connection.url">${db.jdbcurl}</prop>
<prop key="hibernate.connection.username">${db.username}</prop>
<prop key="hibernate.connection.password">${db.password}</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider
</prop>
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.max_size">6</prop>
<prop key="hibernate.c3p0.maxIdleTime">3000</prop>
<prop key="hibernate.c3p0.timeout">5000</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.idle_test_period">3000</prop>
<prop key="hibernate.c3p0.preferredTestQuery">SELECT 1</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql" >false</prop>
<prop key="hibernate.format_sql" >false</prop>
<prop key="hibernate.hbm2ddl.auto" >update</prop>
</props>
</property>
</bean>
以下连接数据:
db.driver = com.mysql.jdbc.Driver
hibernate.dialect = org.hibernate.dialect.MySQLDialect
db.jdbcurl = JDBC:MySQL的://本地主机:3306 / XXXXautoReconnect =真安培; allowMultiQueries =真 db.username = XXXX
db.password = YYYY
db.jdbcurl2 = JDBC:MySQL的://XXXXX-cluster.XXXXXXXX.eu-west-2.rds.amazonaws.com:3306 / XXXX autoReconnect的=真安培; allowMultiQueries =真
db.username2 = XXXX
db.password2 = YYYY
这是我从日志中得到的错误消息:
2017-10-30 12:16:25 WARN ThreadPoolAsynchronousRunner:743 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@6cf38f72 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
2017-10-30 12:16:25 WARN ThreadPoolAsynchronousRunner:759 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@6cf38f72 -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@5371f5ab
on thread: C3P0PooledConnectionPoolManager[identityToken->1bqsmig9ruavayon79lc0|319cb4da]-HelperThread-#0
com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@12e0b3c5
on thread: C3P0PooledConnectionPoolManager[identityToken->1bqsmig9ruavayon79lc0|319cb4da]-HelperThread-#2
com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@2b726e6f
on thread: C3P0PooledConnectionPoolManager[identityToken->1bqsmig9ruavayon79lc0|319cb4da]-HelperThread-#1
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@432689e8
Pool thread stack traces:
Thread[C3P0PooledConnectionPoolManager[identityToken->1bqsmig9ruavayon79lc0|319cb4da]-HelperThread-#0,5,RMI Runtime]
java.net.PlainSocketImpl.socketConnect(Native Method)
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
我尝试将c3p0.max_statements设置为0以及其他许多功能都没有,所以如果您知道如何解决此问题,我正在寻求您的帮助。
我认为值得一提的是,当我在本地使用2个数据源时,一切都工作正常。我创建一个新的RDS实例并将jdbcurl url更改为rds的那一刻,我得到了上面提到的错误消息..
提前谢谢!
答案 0 :(得分:0)
问题是你的RDS数据库的尝试是挂起的 - 既没有失败,也没有成功,提供和异常,只是挂起。当我没有正确配置我的实例以接受来自客户端的连接时,我在AWS上经历过Connection挂起。这可能是你的问题。
测试和调试的一种方法是使用简单的测试程序,例如
import java.sql.*;
public static void main(String[] argv) {
try {
DriverManager.getConnection("dbc:mysql://XXXXX-cluster.XXXXXXXX.eu-west-2.rds.amazonaws.com:3306/XXXX?autoReconnect=true&allowMultiQueries=true","XXXX","YYYY").close();
System.out.println("Successfully acquired and closed a Connection.");
}
catch ( Exception e ) {
e.printStackTrace();
}
}
如果您可以访问某种类型的REPL,那么只需尝试
DriverManager.getConnection("dbc:mysql://XXXXX-cluster.XXXXXXXX.eu-west-2.rds.amazonaws.com:3306/XXXX?autoReconnect=true&allowMultiQueries=true","XXXX","YYYY").close();
如果从您打算运行应用程序的机器成功,那么您的应用程序可能也是如此。