代码之家  ›  专栏  ›  技术社区  ›  cdarwin

在Tomcat-Windows 10下,Hibernate/c3pO无法工作:明显的死锁

  •  0
  • cdarwin  · 技术社区  · 7 年前

    我的应用程序使用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 工作正常

    我用过 Wireshark RawCap 在Windows下捕获连接,似乎连接被获取了,正如日志所说,但在看到Postgres说“准备好查询”后,如果我看得好的话,它们被关闭了。

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

    1 回复  |  直到 7 年前
        1
  •  2
  •   cdarwin    7 年前

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