Tomcat中部署的web服务基本每日一挂

xdjames 发布于 2014/08/05 17:09
阅读 4K+
收藏 0

Hi 各位大侠:

    最近新部署的web服务出现每日一挂的现象,基本上不能撑过10个小时,求各位大侠解答。

具体情况如下:

    使用的服务器为阿里云服务器,操作系统为centos,原先云服务器中已经部署了几个tomcat服务,且使用的的是jdk 1.6.

    新部署的项目基于jdk 1.7开发,故部署时为了不改变原先的环境,新增加了一个tomcat,且在tomcat里面指定了jdk7。这样配置完成之后服务能正常启动且。问题来了,基本上每天早上上班之后来看,前一天部署的该服务再在浏览器打开就会报错了,查询tomcat日志后报错如下,跪求各位大神解答。


以下为详细日志文件:

[2014-08-05 15:00:00] ERROR org.quartz.core.JobRunShell - Job test8.test0008 threw an unhandled Exception: 

org.springframework.transaction.TransactionSystemException: Could not commit JDBC transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:272) ~[spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at com.sun.proxy.$Proxy36.getRegionByName(Unknown Source) ~[na:na]
at com.govcloud.task.KeepJDCBconnectTask.run(KeepJDCBconnectTask.java:19) ~[KeepJDCBconnectTask.class:na]
at com.govcloud.task.QuartzJobFactory.execute(QuartzJobFactory.java:20) ~[QuartzJobFactory.class:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.2.1.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar:na]
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_60]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_60]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_60]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_60]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1757) ~[mysql-connector-java-5.1.29.jar:na]
at sun.reflect.GeneratedMethodAccessor115.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126) ~[tomcat-jdbc-7.0.54.jar:na]
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109) ~[tomcat-jdbc-7.0.54.jar:na]
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80) ~[tomcat-jdbc-7.0.54.jar:na]
at com.sun.proxy.$Proxy75.commit(Unknown Source) ~[na:na]
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:269) ~[spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
... 12 common frames omitted
[2014-08-05 15:00:00] ERROR org.quartz.core.ErrorLogger - Job (test8.test0008 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) ~[quartz-2.2.1.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar:na]
Caused by: org.springframework.transaction.TransactionSystemException: Could not commit JDBC transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:272) ~[spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) ~[spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at com.sun.proxy.$Proxy36.getRegionByName(Unknown Source) ~[na:na]
at com.govcloud.task.KeepJDCBconnectTask.run(KeepJDCBconnectTask.java:19) ~[KeepJDCBconnectTask.class:na]
at com.govcloud.task.QuartzJobFactory.execute(QuartzJobFactory.java:20) ~[QuartzJobFactory.class:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.2.1.jar:na]
... 1 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_60]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_60]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_60]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_60]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920) ~[mysql-connector-java-5.1.29.jar:na]
at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1757) ~[mysql-connector-java-5.1.29.jar:na]
at sun.reflect.GeneratedMethodAccessor115.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_60]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_60]
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126) ~[tomcat-jdbc-7.0.54.jar:na]
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109) ~[tomcat-jdbc-7.0.54.jar:na]
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80) ~[tomcat-jdbc-7.0.54.jar:na]
at com.sun.proxy.$Proxy75.commit(Unknown Source) ~[na:na]
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:269) ~[spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
... 12 common frames omitted
加载中
0
xdjames
xdjames
给各位一个反馈信息,目前问题已解决,原先的检验线程是一小时连接一次数据库,改成十五分钟一次之后程序跑到现在差不多一周时间,还没出现异常。具体原因有大神能解释一下吗?
0
莲莲莲

看这异常好像是定时器中事务提交失败,检查方法事务配置以及Mysql表引擎。

xdjames
xdjames
表引擎是InnoDB,应该没有问题
0
一只小桃子
一只小桃子
同意是数据库连接问题
0
tinshen
tinshen

数据库的连接池是用的什么的。

我们公司我是位了保证系统稳定性,凌晨会重启tomcat的。

xdjames
xdjames
因为是基于spring封装的私有框架,连接池的配置都是已经做好的。具体哪里做的配置我还没找到,不过看maven中引用的jar包连接池用的是c3p0
0
_icode
_icode
mysql主动断开的
0
静风流云
静风流云

Mysql的8小时超时问题?
加个检验语句,每小时检验一下,连接池就不会被数据库单方面断开了。

静风流云
静风流云
回复 @xdjames : 连接池配置的最小连接数(闲置的)大于1,你的检验线程,就有可能总是只请求到其中的一个来校验。其他的连接,可能无法被检验语句执行到。连接池配置方式的检验语句,是连接池自己来管理的,对每个闲置超过一个小时的连接,都去检验一次,保证每个超过1小时闲置时间的连接,重新开始计时。
xdjames
xdjames
刚开始的报错确实是8小时超时问题,后来启了个线程每小时读数据库一次,然后就报这个错了
0
_icode
_icode
  1. Connection conn = null;  
  2.     Statement stmt = null;  
  3.     ResultSet rs = null;  
  4.     int retryCount = 5;  
  5.     boolean transactionCompleted = false;  
  6.     do {  
  7.         try {  
  8.             conn = getConnection(); // assume getting this from a  
  9.                                     // javax.sql.DataSource, or the  
  10.                                     // java.sql.DriverManager  
  11.             conn.setAutoCommit(false);  
  12.             retryCount = 0;  
  13.             stmt = conn.createStatement();  
  14.             String query = "SELECT foo FROM bar ORDER BY baz";  
  15.             rs = stmt.executeQuery(query);  
  16.             while (rs.next()) {  
  17.             }  
  18.             all.close()  
  19.             transactionCompleted = true;  
  20.         } catch (SQLException sqlEx) {  
  21.             String sqlState = sqlEx.getSQLState();  
  22.            // 这个08S01就是这个异常的sql状态。单独处理手动重新链接就可以了。  
  23.             if ("08S01".equals(sqlState) || "40001".equals(sqlState))   
  24.                 {                  
  25.                     retryCount--;              
  26.                  } else {                  
  27.                      retryCount = 0;              
  28.                      }          
  29.          } finally {              
  30.                  all close:          
  31.              }      
  32.       } while (!transactionCompleted && (retryCount > 0));} 

看看innod是不是关闭了

0
loyal
loyal
你的连接关闭了吧?默认tomcat是8小时后无使用就自动断开连接了.
0
_icode
_icode
看看innod是不是关闭了,确认下,看这个貌似是不支持事务的表现呢?不然就是超时了
0
xdjames
xdjames
感谢楼上各位的热心支持,明天到公司后再排查一下
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部