代码之家  ›  专栏  ›  技术社区  ›  Steven Schlansker

当线程都为空时,是否会出现明显的死锁?

  •  27
  • Steven Schlansker  · 技术社区  · 14 年前

    2010-09-16 13:25:00,160 [Timer-0] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@43502400 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
    2010-09-16 13:25:01,407 [Timer-0] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner  - com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@43502400 -- APPARENT DEADLOCK!!! Complete Status:
      Managed Threads: 10
      Active Threads: 0
      Active Tasks:
      Pending Tasks:
        com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@6e4151a7
      Pool thread stack traces:
      Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#6,5,main]
        java.lang.Object.wait(Native Method)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
      Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
        java.lang.Object.wait(Native Method)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
      Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
        java.lang.Object.wait(Native Method)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
      Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
        java.lang.Object.wait(Native Method)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
      Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#5,5,main]
        java.lang.Object.wait(Native Method)
        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:534)
      Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#4,5,main]
        java.lang.Object.wait(Native Method)
    
    ... many more, exact same stack trace
    

     while (true) {
       Runnable myTask;
       synchronized ( ThreadPoolAsynchronousRunner.this ) {
         while ( !should_stop && pendingTasks.size() == 0 )
           ThreadPoolAsynchronousRunner.this.wait( POLL_FOR_STOP_INTERVAL ); // <- here
         if (should_stop) ...
    

    看起来所有的线程都是空闲的。他们在等工作。0个活动线程,只有1个任务要完成。有什么线索表明出了什么问题吗?

    配置如下:

    ds.setUser(userName);
    ds.setPassword(password);
    ds.setMaxPoolSize(16);
    ds.setMaxConnectionAge(1800);
    ds.setAcquireRetryAttempts(4);
    ds.setMaxIdleTime(900);
    ds.setNumHelperThreads(10);
    ds.setCheckoutTimeout(1000);
    
    11 回复  |  直到 14 年前
        1
  •  15
  •   eebbesen user3132728    9 年前

    我刚刚遇到了一个针对Oracle数据库的类似问题,但在我的情况下 Managed Thread Active Thread 计数是一样的。

        Managed Threads: 3
        Active Threads: 3
    

    APPARENT DEADLOCK 错误,因为我正在进行登录审核。

        2013-08-12 11:29:04,910 [Timer-4] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@34996454 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
        2013-08-12 11:29:04,914 [Timer-4] WARN  com.mchange.v2.async.ThreadPoolAsynchronousRunner: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@34996454 -- APPARENT DEADLOCK!!! Complete Status: 
                Managed Threads: 3
                Active Threads: 3
                Active Tasks: 
                        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6730b844 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
                        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2f91ad49 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
                        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@507ac05 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
                Pending Tasks: 
                        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3aae7ed7
        Pool thread stack traces:
                Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
                        java.net.SocketInputStream.socketRead0(Native Method)
                        java.net.SocketInputStream.read(SocketInputStream.java:150)
                        java.net.SocketInputStream.read(SocketInputStream.java:121)
                        oracle.net.ns.Packet.receive(Packet.java:300)
                        oracle.net.ns.DataPacket.receive(DataPacket.java:106)
                        oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:315)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:260)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:185)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:102)
                        oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124)
                        oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80)
                        oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137)
                        oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:290)
                        oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
                        oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:380)
                        oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:760)
                        oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
                        oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
                        oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
                        oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
                        oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
                        com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
                        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
                        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
                        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
                        com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
                        com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
                        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
                        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
                Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
                        java.net.SocketInputStream.socketRead0(Native Method)
                        java.net.SocketInputStream.read(SocketInputStream.java:150)
                        java.net.SocketInputStream.read(SocketInputStream.java:121)
                        oracle.net.ns.Packet.receive(Packet.java:300)
                        oracle.net.ns.DataPacket.receive(DataPacket.java:106)
                        oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:315)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:260)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:185)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:102)
                        oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124)
                        oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80)
                        oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137)
                        oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:290)
                        oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
                        oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:380)
                        oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:760)
                        oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
                        oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
                        oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
                        oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
                        oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
                        com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
                        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
                        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
                        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
                        com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
                        com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
                        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
                        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
                Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
                        java.net.SocketInputStream.socketRead0(Native Method)
                        java.net.SocketInputStream.read(SocketInputStream.java:150)
                        java.net.SocketInputStream.read(SocketInputStream.java:121)
                        oracle.net.ns.Packet.receive(Packet.java:300)
                        oracle.net.ns.DataPacket.receive(DataPacket.java:106)
                        oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:315)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:260)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:185)
                        oracle.net.ns.NetInputStream.read(NetInputStream.java:102)
                        oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124)
                        oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80)
                        oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137)
                        oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:290)
                        oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
                        oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:380)
                        oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:760)
                        oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
                        oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
                        oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
                        oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
                        oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
                        com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
                        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
                        com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
                        com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
                        com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
                        com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
                        com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
                        com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
    
        2
  •  8
  •   Thomas Weber    14 年前

    当一个连接被获取但没有在死锁检测超时内返回到池时,C3P0确定“明显的死锁”。

        3
  •  4
  •   Stephan    11 年前

    ds.setMaxStatements(1000);
    ds.setMaxStatementsPerConnection(100); (the maximum number of prepared statments your system can execute on a single connection)
    

    https://forum.hibernate.org/viewtopic.php?t=947246&highlight=apparent+deadlock+c3p0

    记住在你完成陈述后关闭它们!!

        4
  •  3
  •   HankCa    6 年前

    https://stackoverflow.com/a/18192588/1019307 得到了足够多的票数表明这应该是一个答案。

    我收到这个错误是因为 我无法通过防火墙进入数据库服务器。 看看这是不是你的问题。

        5
  •  1
  •   Steve T    6 年前

    我在google上找到了这个链接,它向我提供了这个问题的线索:

    https://community.oracle.com/thread/339825

    上面写着:

    首先看看OracleServiceXE和OracleXETNSListener服务是否 机器。它必须与tnsnames.ora文件中声明的主机匹配。

    后来它提到了在哪里可以找到tnsnames.ora文件,对我来说它就在这里:

    C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN
    

    查看tnsnames.ora文件,我看到:

    XE =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = MyMachineName-7)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = XE)
        )
      )
    

    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
          (ADDRESS = (PROTOCOL = TCP)(HOST = MyMachineName-7)(PORT = 1521))
        )
      )
    

    然后我打开任务管理器,单击“服务”选项卡,查看“Oracle”服务。我重新启动了:OracleXETNSListener、oraclexeclargent、OracleServiceXE。我再次在eclipse中重新启动tomcat,这次出现了问题。

    附录:

    https://community.oracle.com/thread/2267906

    这让我尝试:

    1) 关闭Windows Defender中的防火墙(已关闭mcaffee防火墙)

    C:\oraclexe\app\oracle\product\11.2.0\server\bin\sqlplus.exe

    3) 已启动Oracle Database 11g的桌面快捷方式

    4) 使用dbVisualizer,我尝试连接到Oracle。这只有在我解决了.ora文件机名称问题后才起作用:双击连接并单击“ping服务器”按钮。

        6
  •  0
  •   atzu    9 年前

    我也遇到过同样的问题,但原因有点难以发现,因为它是由一些同时尝试获取连接的资源引起的。

    如您所知,如果池尚未初始化,则通过调用setup函数初始化它所提供的代码。

    public Connection getConnection() throws SQLException {
        if (mCPDS == null) {
            setupPool();
        }
    
        return mCPDS.getConnection();
    }
    

    解决方案只是声明同步的方法,以便在调用该方法并且该方法仍在实例化池中时将其他资源排除在外。

    public synchronized Connection getConnection() throws SQLException {
        if (mCPDS == null) {
            setupPool();
        }
    
        return mCPDS.getConnection();
    }
    

    这可能是不使用单例的设计错误,但修复了缺乏一些性能的问题。

        7
  •  0
  •   Abhinav Ravi    7 年前

    String SQL = "SELECT 1";
    try {
        con = DriverManager.getConnection(host, userName, userPassword);
        stmt = con.prepareStatement(SQL, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        try {
            rs = stmt.executeQuery(SQL);
            try {
                rs.next();
                // ...
            } finally {
                rs.close();
            }
        } finally {
            stmt.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(MyClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    
        8
  •  0
  •   Alejandro Lopez Morales    6 年前

    嗨,我的朋友刚刚评论,我有同样的情况。我刚刚配置了我的springhibernate eclipse项目,并显示了相同的异常,应该注意的是,我的项目仍然没有任何查询。

    我通过以下步骤解决了该问题:

    2) 生成项目:项目-->生成项目

    我希望它对你有用。

        9
  •  0
  •   Leviand    6 年前

    明显的僵局

    在删除了项目中的所有断点之后,一切又开始顺利了。

        10
  •  -1
  •   colin    8 年前

    我们遇到了这个问题,通过将其添加到C3P0配置中解决了这个问题:

    <property name="statementCacheNumDeferredCloseThreads" value="1"/>
    

    依据: this from the C3P0 doc

        11
  •  -1
  •   packet    7 年前

    在部署应用程序时,glassfish4服务器上也遇到了类似的问题。原来是数据库配置问题。只要确保您的数据库连接配置是正确的,验证配置中提供的主机名是否允许连接到数据库。尝试使用配置的用户名和主机名/域手动连接到数据库。如果需要,允许db用户从所需的域进行连接。使用正确的数据库配置重新生成应用程序,然后部署它。