私のアプリケーションは tomcat+spring+hibernate+mysql に基づいています。tomcat のバージョンは 7.0.25、spring は 2.5、hibernate 3.0、mysql 5.1.53 です。接続プールは c3p0-0.9.1.2.jar、jdbc ドライバーは mysql-connector-java-commercial-5.1.14-bin.jar です。特にテーブルが大きくなると、アプリケーションで多くのデッドロックが発生しました。ここでは、jprofiler による 1 つのデッドロックのスタックをダンプします。
スレッド-1:
com.mysql.jdbc.ConnectionImpl.getCancelTimer()
com.mysql.jdbc.PreparedStatement.executeInternal(int, com.mysql.jdbc.Buffer, boolean, boolean, com.mysql.jdbc.Field[ ], boolean) (line: 2146)
com.mysql.jdbc.PreparedStatement.executeUpdate(byte[ ][ ], java.io.InputStream[ ], boolean[ ], int[ ], boolean[ ], boolean) (line: 2407)
com.mysql.jdbc.PreparedStatement.executeUpdate(boolean, boolean)
com.mysql.jdbc.PreparedStatement.executeUpdate()
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate() (line: 105)
org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(org.hibernate.engine.QueryParameters, org.hibernate.engine.SessionImplementor) (line: 189)
org.hibernate.impl.SessionImpl.executeNativeUpdate(org.hibernate.engine.query.sql.NativeSQLQuerySpecification, org.hibernate.engine.QueryParameters) (line: 1190)
org.hibernate.impl.SQLQueryImpl.executeUpdate() (line: 357)
com.aaabbbccc.intune.dao.DaoHelper.executeUpdateFromSQLQuery(java.lang.String)
com.aaabbbccc.intune.dao.EventDao.deleteEventCountByUser(int) (line: 138)
com.aaabbbccc.intune.statistics.EventStatisticsService.collectEventCountInfoByUser(short, int, int) (line: 134)
com.aaabbbccc.intune.statistics.EventStatisticsService.collectEventCountInfo() (line: 78)
com.aaabbbccc.intune.statistics.EventStatisticsService$$FastClassByCGLIB$$23967f0c.invoke(int, java.lang.Object, java.lang.Object[ ])
net.sf.cglib.proxy.MethodProxy.invoke(java.lang.Object, java.lang.Object[ ]) (line: 149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint()
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed() (line: 149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(org.aopalliance.intercept.MethodInvocation) (line: 106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed()
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[ ], net.sf.cglib.proxy.MethodProxy) (line: 635)
com.aaabbbccc.intune.statistics.EventStatisticsService$$EnhancerByCGLIB$$c70cea1b.collectEventCountInfo()
sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[ ])
sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[ ])
sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[ ])
java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[ ])
org.springframework.util.MethodInvoker.invoke()
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(org.quartz.JobExecutionContext) (line: 260)
org.springframework.scheduling.quartz.QuartzJobBean.execute(org.quartz.JobExecutionContext) (line: 86)
org.quartz.core.JobRunShell.run() (line: 216)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run() (line: 549)
スレッド-2:
com.mysql.jdbc.ConnectionImpl.rollback() (line: 4711)
com.mysql.jdbc.ConnectionImpl.realClose(boolean, boolean, boolean, java.lang.Throwable) (line: 4345)
com.mysql.jdbc.ConnectionImpl.close() (line: 1564)
com.mchange.v2.c3p0.impl.NewPooledConnection.close(java.lang.Throwable) (line: 549)
com.mchange.v2.c3p0.impl.NewPooledConnection.close()
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(java.lang.Object) (line: 470)
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run() (line: 964)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run() (line: 547)
tomcat server.xml の C3P0 構成は次のとおりです。
<Resource type="com.mchange.v2.c3p0.ComboPooledDataSource"
jdbcUrl="jdbc:mysql://localhost/itms?max_sp_recursion_depth=10"
factory="org.apache.naming.factory.BeanFactory"
description="DB Connection"
name="jdbc/pooledDS"
driverClass="com.mysql.jdbc.Driver"
debugUnreturnedConnectionStackTraces="true"
auth="Container"
acquireIncrement="1"
acquireRetryAttempts="10"
idleConnectionTestPeriod="30"
initialPoolSize="15"
maxIdleTime="900"
maxPoolSize="50"
maxStatements="0"
minPoolSize="15"
numHelperThreads="10"
unreturnedConnectionTimeout="900"
user="root"
password="admin" />
私の設定は間違っていますか?助けてください
別のデッドロック:
スレッド-3:
com.mysql.jdbc.ConnectionImpl.execSQL(com.mysql.jdbc.StatementImpl, java.lang.String, int, com.mysql.jdbc.Buffer, int, int, boolean, java.lang.String, com.mysql.jdbc.Field[ ], boolean) (line: 2585)
com.mysql.jdbc.ConnectionImpl.setTransactionIsolation(int) (line: 5318)
com.mchange.v2.c3p0.impl.NewProxyConnection.setTransactionIsolation(int) (line: 701)
sun.reflect.GeneratedMethodAccessor223.invoke(java.lang.Object, java.lang.Object[ ])
sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[ ])
java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[ ])
org.hibernate.jdbc.BorrowedConnectionProxy.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[ ]) (line: 74)
$Proxy21.setTransactionIsolation(int)
org.springframework.jdbc.datasource.DataSourceUtils.resetConnectionAfterTransaction(java.sql.Connection, java.lang.Integer) (line: 196)
org.springframework.orm.hibernate3.HibernateTransactionManager.doCleanupAfterCompletion(java.lang.Object) (line: 628)
org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(org.springframework.transaction.support.DefaultTransactionStatus) (line: 989)
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(org.springframework.transaction.support.DefaultTransactionStatus) (line: 782)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(org.springframework.transaction.TransactionStatus) (line: 701)
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(org.springframework.transaction.interceptor.TransactionAspectSupport$TransactionInfo) (line: 321)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(org.aopalliance.intercept.MethodInvocation) (line: 116)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed()
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[ ], net.sf.cglib.proxy.MethodProxy) (line: 635)
com.aaabbbccc.intune.web.peer.http.TR069PeerService$$EnhancerByCGLIB$$2138ec73.authenticateDevice(java.lang.String, java.util.ArrayList)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.processInform(javax.xml.soap.SOAPMessage, com.aaabbbccc.intune.tr069.models.structs.HeaderStruct, java.lang.String) (line: 1527)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.processingSoapBody(javax.xml.soap.SOAPBody, javax.xml.soap.SOAPMessage, com.aaabbbccc.intune.tr069.models.structs.HeaderStruct, java.lang.Integer, java.lang.String, java.lang.String) (line: 523)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.processSOAPMessage(javax.xml.soap.SOAPMessage, java.lang.Integer, java.lang.String, java.lang.String) (line: 387)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) (line: 194)
javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 722)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 305)
org.apache.catalina.core.ApplicationFilterChain.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 210)
org.apache.catalina.core.ApplicationDispatcher.invoke(javax.servlet.ServletRequest, javax.servlet.ServletResponse, org.apache.catalina.core.ApplicationDispatcher$State) (line: 684)
org.apache.catalina.core.ApplicationDispatcher.doInclude(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.DispatcherType) (line: 593)
org.apache.catalina.core.ApplicationDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 530)
org.apache.catalina.core.AsyncContextImpl$1.run() (line: 174)
org.apache.catalina.core.AsyncContextImpl.doInternalDispatch() (line: 316)
org.apache.catalina.core.StandardWrapperValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 202)
org.apache.catalina.core.StandardContextValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 169)
org.apache.catalina.core.StandardHostValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 168)
org.apache.catalina.valves.ErrorReportValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 98)
org.apache.catalina.core.StandardEngineValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 118)
org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(org.apache.coyote.Request, org.apache.coyote.Response, org.apache.tomcat.util.net.SocketStatus) (line: 298)
org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(org.apache.tomcat.util.net.SocketStatus) (line: 1515)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(org.apache.tomcat.util.net.SocketWrapper, org.apache.tomcat.util.net.SocketStatus) (line: 563)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run() (line: 1600)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(java.lang.Runnable)
java.util.concurrent.ThreadPoolExecutor$Worker.run()
java.lang.Thread.run()
スレッド-4:
com.mysql.jdbc.ConnectionImpl.getCancelTimer()
com.mysql.jdbc.PreparedStatement.executeInternal(int, com.mysql.jdbc.Buffer, boolean, boolean, com.mysql.jdbc.Field[ ], boolean) (line: 2119)
com.mysql.jdbc.PreparedStatement.executeQuery() (line: 2273)
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery() (line: 76)
org.hibernate.jdbc.AbstractBatcher.getResultSet(java.sql.PreparedStatement) (line: 208)
org.hibernate.loader.Loader.getResultSet(java.sql.PreparedStatement, boolean, boolean, org.hibernate.engine.RowSelection, org.hibernate.engine.SessionImplementor) (line: 1808)
org.hibernate.loader.Loader.doQuery(org.hibernate.engine.SessionImplementor, org.hibernate.engine.QueryParameters, boolean) (line: 697)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(org.hibernate.engine.SessionImplementor, org.hibernate.engine.QueryParameters, boolean) (line: 259)
org.hibernate.loader.Loader.loadEntity(org.hibernate.engine.SessionImplementor, java.lang.Object, org.hibernate.type.Type, java.lang.Object, java.lang.String, java.io.Serializable, org.hibernate.persister.entity.EntityPersister) (line: 1881)
org.hibernate.loader.entity.AbstractEntityLoader.load(org.hibernate.engine.SessionImplementor, java.lang.Object, java.lang.Object, java.io.Serializable) (line: 71)
org.hibernate.loader.entity.AbstractEntityLoader.load(java.io.Serializable, java.lang.Object, org.hibernate.engine.SessionImplementor)
org.hibernate.persister.entity.AbstractEntityPersister.load(java.io.Serializable, java.lang.Object, org.hibernate.LockMode, org.hibernate.engine.SessionImplementor)
org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEventListener$LoadType) (line: 434)
org.hibernate.event.def.DefaultLoadEventListener.doLoad(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEventListener$LoadType)
org.hibernate.event.def.DefaultLoadEventListener.load(org.hibernate.event.LoadEvent, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.EntityKey, org.hibernate.event.LoadEventListener$LoadType) (line: 165)
org.hibernate.event.def.DefaultLoadEventListener.onLoad(org.hibernate.event.LoadEvent, org.hibernate.event.LoadEventListener$LoadType) (line: 121)
org.hibernate.impl.SessionImpl.fireLoad(org.hibernate.event.LoadEvent, org.hibernate.event.LoadEventListener$LoadType) (line: 905)
org.hibernate.impl.SessionImpl.immediateLoad(java.lang.String, java.io.Serializable) (line: 863)
org.hibernate.proxy.AbstractLazyInitializer.initialize() (line: 95)
org.hibernate.proxy.AbstractLazyInitializer.getImplementation() (line: 140)
org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.reflect.Method, java.lang.Object[ ]) (line: 190)
com.aaabbbccc.intune.data.ProviderMaster_$$_javassist_23.getAutoApproveMode()
com.aaabbbccc.intune.web.peer.http.TR069PeerService.authenticateDevice(java.lang.String, java.util.ArrayList) (line: 882)
com.aaabbbccc.intune.web.peer.http.TR069PeerService$$FastClassByCGLIB$$455c8769.invoke(int, java.lang.Object, java.lang.Object[ ])
net.sf.cglib.proxy.MethodProxy.invoke(java.lang.Object, java.lang.Object[ ]) (line: 149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint()
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed() (line: 149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(org.aopalliance.intercept.MethodInvocation) (line: 106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed()
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[ ], net.sf.cglib.proxy.MethodProxy) (line: 635)
com.aaabbbccc.intune.web.peer.http.TR069PeerService$$EnhancerByCGLIB$$2138ec73.authenticateDevice(java.lang.String, java.util.ArrayList)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.processInform(javax.xml.soap.SOAPMessage, com.aaabbbccc.intune.tr069.models.structs.HeaderStruct, java.lang.String) (line: 1527)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.processingSoapBody(javax.xml.soap.SOAPBody, javax.xml.soap.SOAPMessage, com.aaabbbccc.intune.tr069.models.structs.HeaderStruct, java.lang.Integer, java.lang.String, java.lang.String) (line: 523)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.processSOAPMessage(javax.xml.soap.SOAPMessage, java.lang.Integer, java.lang.String, java.lang.String) (line: 387)
com.aaabbbccc.intune.web.peer.http.TR069AsyncServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) (line: 194)
javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 722)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 305)
org.apache.catalina.core.ApplicationFilterChain.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 210)
org.apache.catalina.core.ApplicationDispatcher.invoke(javax.servlet.ServletRequest, javax.servlet.ServletResponse, org.apache.catalina.core.ApplicationDispatcher$State) (line: 684)
org.apache.catalina.core.ApplicationDispatcher.doInclude(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.DispatcherType) (line: 593)
org.apache.catalina.core.ApplicationDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse) (line: 530)
org.apache.catalina.core.AsyncContextImpl$1.run() (line: 174)
org.apache.catalina.core.AsyncContextImpl.doInternalDispatch() (line: 316)
org.apache.catalina.core.StandardWrapperValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 202)
org.apache.catalina.core.StandardContextValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 169)
org.apache.catalina.core.StandardHostValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 168)
org.apache.catalina.valves.ErrorReportValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 98)
org.apache.catalina.core.StandardEngineValve.invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response) (line: 118)
org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(org.apache.coyote.Request, org.apache.coyote.Response, org.apache.tomcat.util.net.SocketStatus) (line: 298)
org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(org.apache.tomcat.util.net.SocketStatus) (line: 1515)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(org.apache.tomcat.util.net.SocketWrapper, org.apache.tomcat.util.net.SocketStatus) (line: 563)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run() (line: 1600)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(java.lang.Runnable)
java.util.concurrent.ThreadPoolExecutor$Worker.run()
java.lang.Thread.run()