启动tomcat时报了下面的错:
发现报了该错后并不影响系统的功能,事务数据库操作什么的都是OK的,这个错误比较奇怪:如果事务无法开启,那后面的数据库操作应该都无法进行才对呀,可是事实上又不是这样
后来发现是每次把服务器加电开启时才会报这个错,由于我的mysql tomcat等服务都是在开机时自启动的或者是被watchdog自动叫起来的,于是就在想是不是在开机时mysql服务没有完全启动引起的,后来经过测试确定是该原因
于是在tomcat的startup.sh脚本中加上以下语句:
这样就避免了该错误的发生
=2013-08-06 10:52:37,849 ERROR [Timer-5] timer.SystemMonitoringTimer (SystemMonitoringTimer.java:331) - oops, got an exception:
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed:
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:440)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy22.getAllThresholdInfo(Unknown Source)
at com.xxxxxxx.oam.systemmonitoring.timer.SystemMonitoringTimer.run(SystemMonitoringTimer.java:108)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: org.hibernate.TransactionException: JDBC begin transaction failed:
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:76)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1309)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:399)
... 11 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 9,961 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3052)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2938)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3481)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:5034)
at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:881)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:72)
... 14 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2497)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2949)
... 22 more
发现报了该错后并不影响系统的功能,事务数据库操作什么的都是OK的,这个错误比较奇怪:如果事务无法开启,那后面的数据库操作应该都无法进行才对呀,可是事实上又不是这样
后来发现是每次把服务器加电开启时才会报这个错,由于我的mysql tomcat等服务都是在开机时自启动的或者是被watchdog自动叫起来的,于是就在想是不是在开机时mysql服务没有完全启动引起的,后来经过测试确定是该原因
于是在tomcat的startup.sh脚本中加上以下语句:
#判断进程mysqld 是否存在,如果不存在就启动它
echo "check The mysqld whether running"
PIDS=`ps -ef |grep mysqld |grep -v grep | awk '{print $2}'`
while [ "$PIDS"x == ""x ]; do
echo "The mysqld is not running"
service mysqld start
sleep 5
PIDS=`ps -ef |grep mysqld |grep -v grep | awk '{print $2}'`
done
echo "The mysqld is running"
这样就避免了该错误的发生