2013-12-16 103 views
1

我哈瓦Web服務器與MySQL,一些配置初級講座:通信鏈路故障時,在MySQL中執行的程序

mysql: mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1 
spring: 3.05 
mysql-driver:5.1.13 

此異常最早出現的時間大約爲2013-12-13 02:33,然後我做的有些事情:
1,向mysql url添加autoReconnect=true;
2,將<property name="houseKeepingTestSql" value="select CURRENT_DATE"></property>添加到ProxoolDataSource configuratin。

我以爲這個bug是固定的,但我錯了,這個異常再次出現了,幾乎在同一時間(2013-12-16 02:33)。

這是堆棧跟蹤:

The last packet successfully received from the server was 131,609 milliseconds ago. The last packet sent successfully to the server was 2 milliseconds ago. 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_41] 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_41] 
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_41] 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_41] 
     at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3055) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2941) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3489) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1364) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.CallableStatement.execute(CallableStatement.java:879) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at sun.reflect.GeneratedMethodAccessor121.invoke(Unknown Source) ~[na:na] 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_41] 
     at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_41] 
     at org.logicalcobwebs.proxool.ProxyStatement.invoke(ProxyStatement.java:100) ~[proxool-0.9.1.jar:na] 
     at org.logicalcobwebs.proxool.ProxyStatement.intercept(ProxyStatement.java:57) ~[proxool-0.9.1.jar:na] 
     at $java.sql.Wrapper$$EnhancerByProxool$$df6af44.execute(<generated>) ~[proxool-cglib.jar:na] 
     at sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source) ~[na:na] 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_41] 
     at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_41] 
     at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:58) ~[mybatis-3.1.1.jar:3.1.1] 
     at com.sun.proxy.$Proxy39.execute(Unknown Source) ~[na:na] 
     at org.apache.ibatis.executor.statement.CallableStatementHandler.query(CallableStatementHandler.java:63) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95) ~[mybatis-3.1.1.jar:3.1.1] 
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59) ~[mybatis-3.1.1.jar:3.1.1] 
     at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source) ~[na:na] 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_41] 
     at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_41] 
     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355) ~[mybatis-spring-1.1.1.jar:1.1.1] 
     ... 28 common frames omitted 
Caused by: java.net.SocketException: Socket closed 
     at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.6.0_41] 
     at java.net.SocketInputStream.read(SocketInputStream.java:129) ~[na:1.6.0_41] 
     at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189) ~[mysql-connector-java-5.1.13-bin.jar:na] 
     at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2499) ~[mysql-connector-java-5.1.13-bin.jar:na] 

始終把程序querprize()拋出此異常,其他人查詢似乎正常。 你能幫我解決這個問題嗎?
提前致謝。

編輯
我必須解決這個問題,在上午02時33分,在此服務器上的MySQL是備份數據,那麼多I/O操作運行,並在我的項目中maxActiveConnectionTime只是120000毫秒。 Proxool數據源在過程完成並返回之前關閉了當前連接,這就是爲什麼Socket closed異常發生在這種情況下。所以我的解決方案設置了maxActiveConnectionTime很多。

+0

[link1](http://stackoverflow.com/a/2840358/1031945)。 [link2](http://stackoverflow.com/a/2985169/1031945) –

+0

MySQL和您的應用程序是否在同一主機上運行? –

+0

不,他們在不同的服務器上。 – znlyj

回答

1

在看看this

它似乎除了autoReconnect=true URL附屬物,以下性的判定,將有助於:

,如果你在春季使用DBCP作爲連接池,添加以下條目您的數據源定義

<bean id="datasource" destroy-method="close"> 
<property name="driverClassName」 value="${.jdbc.driver}" /> 
<property name="url" value="${jdbc.url}" /> 
<property name="username" value="${jdbc.username}" /> 
<property name="password" value="${jdbc.password}" /> 
<property name="validationQuery" value="SELECT 1" /> <--- This 
<property name="testOnBorrow" value="true" />   <---- and this 
</bean> 

,如果你在春季使用C3P0作爲連接池,將以下條目添加到您的數據源定義

<bean id=」pooledDataSource」 class=」com.mchange.v2.c3p0.ComboPooledDataSource」 destroy-method=」close」> 

<property name=」driverClass」 value=」${driver}」></property> 
<property name=」jdbcUrl」 value=」${url}」 /> 
<property name=」user」 value=」${username}」 /> 
<property name=」password」 value=」${password}」 /> 
<property name=」initialPoolSize」 value=」20″ /> 
<property name=」minPoolSize」 value=」10″ /> 
<property name=」maxPoolSize」 value=」50″ /> 
<property name=」checkoutTimeout」 value=」1000″ /> 
<property name=」maxStatements」 value=」500″ /> 
<property name=」testConnectionOnCheckin」 value=」false」 /> <---- this 
<property name=」testConnectionOnCheckout」 value=」true」 /> <- and this 
<property name=」maxIdleTime」 value=」1800″ /> 
<property name=」idleConnectionTestPeriod」 value=」1000″ /> 
</bean> 
相關問題