多个程序访问一个数据库出现死锁,怎么处理?
良少
博客专家认证 2007-12-04 05:08:32 我们有2个程序访问同一个数据库。一个是用Spring+iBatis 访问数据库,我写的程序使用Hibernate+C3p0的数据库连接池访问。 数据库是MySQL。
现在,我这边经常报错。 显示数据库死锁, 无法同步事务的状态。
请问各位,在这种情况下是怎么处理的?
经常出现下面的警告信息:
2007-12-03 21:14:07,453 WARN [com.mchange.v2.async.ThreadPoolAsynchronousRunner] - Task com.mchange.v2.c3p0.stmt.GooGooStatementCache$1@2e0dcb (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt().
然后是出错信息:
2007-12-03 21:14:41,984 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1205, SQLState: 41000
2007-12-03 21:14:41,984 ERROR [org.hibernate.util.JDBCExceptionReporter] - Lock wait timeout exceeded; try restarting transaction
2007-12-03 21:14:41,984 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.withub.adserver.frontserver.persistent.service.traceMessage.TraceMessageService.saveTX(TraceMessageService.java:61)
at com.withub.adserver.frontserver.frontserver.nio.server.interpreter.BaseMessageInterpreter.saveTraceMessage(BaseMessageInterpreter.java:372)
at com.withub.adserver.frontserver.frontserver.nio.server.interpreter.BaseMessageInterpreter.checkAndTraceMessage(BaseMessageInterpreter.java:149)
at com.withub.adserver.frontserver.frontserver.nio.server.interpreter.ClientREQWatchHardwareState.interpreter(ClientREQWatchHardwareState.java:72)
at com.withub.adserver.frontserver.frontserver.runnable.DealRequsetWorker.dealRequest(DealRequsetWorker.java:162)
at com.withub.adserver.frontserver.frontserver.runnable.DealRequsetWorker.run(DealRequsetWorker.java:226)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:656)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 16 more