Hibernate/c3pO 在 Tomcat 下不起作用 - Windows 10:明显的死锁

Hibernate/c3pO doesn't work under Tomcat - Windows 10: apparent deadlock

我的应用程序使用 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 日志我看到有很多连接,直到数据库说它不能分配更多。连接远高于 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 下的 Wireshark and RawCap 来捕获连接,看起来连接已获取,如日志所述,但在看到 Postgres 说 "ready for queries" 后,它们已关闭,如果我看得好。

我还能查看什么来调试正在发生的事情??

原来是我用错了postgresql驱动。我有 java 8,使用 PostgreSQL JDBC 4.2 Driver, 42.1.4 解决了问题。