JFinal C3p0Plugin 插件连接mysql经常出现死锁

@JFinal  目前使用jfinal的最新版本,通过C3p0插件连接mysql数据库:

        public static C3p0Plugin createC3p0Plugin() {
		return new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}
	
	@Override
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin C3p0Plugin = createC3p0Plugin();
		me.add(C3p0Plugin);
				
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(C3p0Plugin);
		arp.setShowSql(true);
		me.add(arp);
				
		// 所有配置在 MappingKit 中搞定
		_MappingKit.mapping(arp);
	}

经常会出现 APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!  死锁的情况,异常信息如下:

2016-12-21 08:11:50
[WARN]-[Thread: Timer-0]-[com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector.run()]: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1b3bf45b -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

2016-12-21 08:11:50
[WARN]-[Thread: Timer-0]-[com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector.run()]: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@1b3bf45b -- APPARENT DEADLOCK!!! Complete Status: 
	Managed Threads: 3
	Active Threads: 3
	Active Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2b4e64c2 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@27b912c4 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@677f163b (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
	Pending Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@488cb092
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@c9c6674
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@700a5023
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3513634c
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@bdc2dcd
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2442f3d0
		com.mchange.v2.resourcepool.BasicResourcePool$1RefurbishCheckinResourceTask@2794ef49
Pool thread stack traces:
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
		java.net.SocketInputStream.socketRead0(Native Method)
		java.net.SocketInputStream.read(SocketInputStream.java:152)
		java.net.SocketInputStream.read(SocketInputStream.java:122)
		com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101)
		com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144)
		com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174)
		com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3001)
		com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3462)
		com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3452)
		com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3893)
		com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
		com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
		com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
		com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
		com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
		com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3833)
		com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3283)
		com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2297)
		com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
		com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
		com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
		sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
		sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
		sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
		java.lang.reflect.Constructor.newInstance(Constructor.java:526)
		com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
		com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
		com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
		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-#2,5,main]
		java.net.SocketInputStream.socketRead0(Native Method)
		java.net.SocketInputStream.read(SocketInputStream.java:152)
		java.net.SocketInputStream.read(SocketInputStream.java:122)
		com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101)
		com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144)
		com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174)
		com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3001)
		com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3462)
		com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3452)
		com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3893)
		com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
		com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
		com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
		com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
		com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
		com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3833)
		com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3283)
		com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2297)
		com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
		com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
		com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
		sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
		sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
		sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
		java.lang.reflect.Constructor.newInstance(Constructor.java:526)
		com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
		com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
		com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
		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:152)
		java.net.SocketInputStream.read(SocketInputStream.java:122)
		com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101)
		com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144)
		com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174)
		com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3001)
		com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3462)
		com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3452)
		com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3893)
		com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)
		com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)
		com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
		com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
		com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
		com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3833)
		com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3283)
		com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2297)
		com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
		com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
		com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
		sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
		sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
		sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
		java.lang.reflect.Constructor.newInstance(Constructor.java:526)
		com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
		com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
		com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
		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)
、
不知道各位有没有出现这种情况?  如何解决? @JFinal


评论区

luorongda

2016-12-21 09:36

使用DruidPlugin吧。

JFinal

2016-12-21 12:23

c3p0 太老了,换上 DruidPlugin 以后啥事也没有

空指针

2016-12-21 13:35

@JFinal 换druid-0.2.17 这个版本了

空指针

2016-12-21 13:36

@JFinal 建议把jfinal中的默认连接池也改了吧

JFinal

2016-12-21 14:11

@空指针 是个好主意,这次 jfinal 2.3 发布将会把所有 c3p0 的全部改成 DruidPlugin

IvyHelen

2016-12-22 21:31

@JFinal 对, 我们拿下来项目都,首要完成的任务就是干掉c3p0换上Druid

张大一

2018-07-19 08:55

以后再也不用c3p0了,问题太多,

热门反馈

扫码入社