数据库连接错误

项目架构struts2+hibernate+spring有一个每隔一秒的spring定时器执行数据库的增删改查操作
事物配置如下:
<!-- 指定事务管理器 -->
proxy-target-class="true" />
<!-- 配置事务的传播特性 -->

<!-- 配置一个切入点,匹配dao包下 所有以Impl结尾的类的所有方法的执行 -->

<!-- 指定在txAdvice切入点应用txAdvice事务切面 -->
/aop:config

tx:attributes








/tx:attributes
/tx:advice
当使用此配置时(定时任务执行一段时间后)出现如下异常:
Exception in thread "com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1" java.lang.OutOfMemoryError: Java heap space
当使用如下配置时:
<!-- 指定事务管理器 -->
proxy-target-class="true" />
<!-- 配置事务的传播特性 -->

<!-- 配置一个切入点,匹配dao包下 所有以Impl结尾的类的所有方法的执行 -->

<!-- 指定在txAdvice切入点应用txAdvice事务切面 -->
/aop:config

tx:attributes








/tx:attributes
/tx:advice
注:此配置事物直接指定到了定时器的service层,但是定时任务执行一段时间后程序报如下错误:
2012-07-30 09:51:19,716 ERROR [org.quartz.core.ErrorLogger] - [Job (DEFAULT.upCompanyMatchJobDetail threw an exception.]
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:534)
Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:354)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:103)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:625)
at com.lyn.job.company.service.impl.UpCompanyMatchManagerServiceImpl$$EnhancerByCGLIB$$a5f981c9.match()
at com.lyn.job.company.UpCompanyMatchJob.execute(UpCompanyMatchJob.java:20)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
... 1 more
Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
... 11 more
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 16 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 19 more
急求指点,万分感谢!

1个回答

Cannot open connection。数据库连接错,
1.确定数据库服务打开
2.使用数据库是否存在

iteye_5246
iteye_5246 哥们我也没帮什么忙啊。。对于事物控制在service,貌似你在dao里了。
接近 8 年之前 回复
chenfang8712
IT菜鸟2018 数据库已经打开,定时线程可以执行十几二十分钟,之后就出现上述问题。另外小弟有两个疑问:两种配置事物<aop:advisor pointcut="execution(* com.lyn.job.company.service.impl.UpCompanyMatchManagerServiceImpl.*(..))" advice-ref="txAdvice" /> 与<aop:advisor pointcut="execution(* *..*DaoImpl.*(..))" advice-ref="txAdvice" /> 哪一个正确使用上了,或者是都没有引用上,求解答,谢谢!
接近 8 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问