【问题标题】:Hibernate/c3pO doesn't work under Tomcat - Windows 10: apparent deadlockHibernate/c3pO 在 Tomcat 下不起作用 - Windows 10:明显的死锁
【发布时间】:2018-05-11 01:09:30
【问题描述】:

我的应用程序使用 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 说“准备查询”之后,如果我看得很清楚,它们就关闭了.

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

【问题讨论】:

    标签: windows eclipse hibernate tomcat c3p0


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 2020-04-03
      • 2019-03-15
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多