Hibernate / c3pO在Tomcat下无法运行 - Windows 10:明显的死锁

时间:2017-11-27 17:50:36

标签: windows eclipse hibernate tomcat c3p0

我的应用程序使用Hibernate和c3po,并且不会在Windows 10 + eclipse Oxygen + Tomcat 8下启动,而在Linux下使用相同的配置工作正常。

这些是控制台在启动Tomcat时显示的一些行

2017/11/27 18:21:03 WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@15cc07ce -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

这应该是报告here的连接问题。

这似乎得到了我得到的例外证实:

2017/11/27 18:21:14 WARN  com.mchange.v2.resourcepool.BasicResourcePool  - com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1e723184 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
org.postgresql.util.PSQLException: FATALE: the remaining connection slots are reserveed to non replica superusers connections
    at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:469)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
    at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
    at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:393)

从postgresql日志中我看到有很多连接,直到db说它无法分配更多。连接远远超过10,而我在hibernate.cfg.xml

中有这个
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">3</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>

psql -h localhost -U user db工作正常

我在Windows下使用WiresharkRawCap来捕获连接,并且似乎已经获得了连接,正如日志所说,但看到Postgres说&#34;准备好查询&#34;如果我看得好,他们就会被关闭。

我还可以看一下调试发生了什么?

1 个答案:

答案 0 :(得分:1)

事实证明我使用的是错误的postgresql驱动程序。我有java 8,使用PostgreSQL JDBC 4.2 Driver, 42.1.4解决了这个问题。