java.net.SocketException: Broken pipe (Write failed)

如果程序不重启,到第二天就会报这个错,根据网上说的,调整mysql的连接时间,我们数据库连接的mycat,mysql的间隔时间已经调整到了24个小时,还是报错:

[2019-09-04 15:33:06,196] (BaseJdbcLogger.java:142) DEBUG [pool-1-thread-2] jdbc.BaseJdbcLogger (BaseJdbcLogger.java:142) - ==>  Prep
aring: select workorder_number as workorderNumber, sp_code as spCode, create_date as createDate from CONSISTENCY_WORK_SP_RANGE WHERE 
workorder_number=? 
[2019-09-04 15:33:06,196] (BaseJdbcLogger.java:142) DEBUG [pool-1-thread-2] jdbc.BaseJdbcLogger (BaseJdbcLogger.java:142) - ==> Param
eters: 2(Integer)
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received f
rom the server was 169,794,818 milliseconds ago.  The last packet sent successfully to the server was 169,795,024 milliseconds ago. i
s longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity b
efore use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection prope
rty 'autoReconnect=true' to avoid this problem.
### The error may exist in com/test/send/mapper/ConsistencyWorkSpRangeMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select         workorder_number as workorderNumber,    sp_code as spCode,    create_date as createDate    from CONSISTENCY_W
ORK_SP_RANGE    WHERE workorder_number=?
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 169,794
,818 milliseconds ago.  The last packet sent successfully to the server was 169,795,024 milliseconds ago. is longer than the server c
onfigured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your applicat
ion, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' t
o avoid this problem.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
        at com.sun.proxy.$Proxy10.selectConsistencyWorkSpRange(Unknown Source)
        at com.test.send.dao.ConsistencyWorkSpRangeDao.selectConsistencyWorkSpRange(ConsistencyWorkSpRangeDao.java:32)
        at com.test.send.service.impl.ConsistencyWorkSpRangeServiceImpl.selectConsistencyWorkSpRange(ConsistencyWorkSpRangeServic
eImpl.java:30)
        at com.test.send.sendreq.ReqResult4Json.sendJsonReqString(ReqResult4Json.java:185)
        at com.test.send.sendreq.SendJsonJob.jobStart(SendJsonJob.java:89)
        at com.test.send.JobStart$1.run(JobStart.java:26)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 169,794
,818 milliseconds ago.  The last packet sent successfully to the server was 169,795,024 milliseconds ago. is longer than the server c
onfigured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your applicat
ion, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' t
o avoid this problem.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3965)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2578)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2758)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2826)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
        at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1302)
        at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
        at com.sun.proxy.$Proxy4.execute(Unknown Source)
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:62)
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78)
        at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
        ... 17 more
Caused by: java.net.SocketException: Broken pipe (Write failed)
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3946)
        ... 35 more
java.lang.NullPointerException
        at com.test.send.sendreq.ReqResult4Json.sendJsonReqString(ReqResult4Json.java:186)
        at com.test.send.sendreq.SendJsonJob.jobStart(SendJsonJob.java:89)
        at com.test.send.JobStart$1.run(JobStart.java:26)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
[2019-09-04 15:33:06,212] (JobStart.java:28) INFO  [pool-1-thread-2] send.JobStart$1 (JobStart.java:28) - end this job......
[2019-09-04 15:33:06,212] (JobStart.java:29) INFO  [pool-1-thread-2] send.JobStart$1 (JobStart.java:29) - -*-*-*-*-*-*-*-*--  spend t
otal time:117 ms -*-*-*-*-*-*-*-*-

另外一种报错:

[2019-09-10 13:59:36,665] (BaseJdbcLogger.java:142) DEBUG [pool-1-thread-1] jdbc.BaseJdbcLogger (BaseJdbcLogger.java:142) - ==> Parameters: 2(Integer), 00000010(String)
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 13,799,967 milliseconds ago.  The last packet sent successfully to the server was 11,999,999 milliseconds ago.
### The error may exist in com/test/send/mapper/ConsistencyWorkOrderMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select         workorder_number as workorderNumber,       opr_numb as oprNumb,    data_type as dataType,    consistency_type as consistencyType,    valid_time_start as validTimeStart,    valid_time_end as validTimeEnd,    status as status,    create_date as createDate,    update_date as updateDate        from CONSISTENCY_WORK_ORDER     where status=?     or status=3    and data_type=?       order by  status
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 13,799,967 milliseconds ago.  The last packet sent successfully to the server was 11,999,999 milliseconds ago.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
        at com.sun.proxy.$Proxy6.selectConsistencyWorkOrder(Unknown Source)
        at com.test.send.dao.ConsistencyWorkOrderDao.selectConsistencyWorkOrder(ConsistencyWorkOrderDao.java:20)
        at com.test.send.service.impl.ConsistencyWorkOrderServiceImpl.selectConsistencyWorkOrder(ConsistencyWorkOrderServiceImpl.java:17)
        at com.test.send.sendreq.Result4Sql.queryConsistencyWorkOrderList(Result4Sql.java:33)
        at com.test.send.sendreq.SendJsonJob.jobStart(SendJsonJob.java:25)
        at com.test.send.JobStart$1.run(JobStart.java:26)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 13,799,967 milliseconds ago.  The last packet sent successfully to the server was 11,999,999 milliseconds ago.
        at sun.reflect.GeneratedConstructorAccessor24.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3965)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2578)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2758)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2826)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
        at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1302)
        at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
        at com.sun.proxy.$Proxy4.execute(Unknown Source)
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:62)
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:78)
        at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
        ... 17 more
Caused by: java.net.SocketException: Broken pipe (Write failed)
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3946)
        ... 35 more
[2019-09-10 13:59:36,667] (SendJsonJob.java:168) DEBUG [pool-1-thread-1] sendreq.SendJsonJob (SendJsonJob.java:168) - reading workorder Table again  after 10 minutes 

我的连接池信息:

 
			type="JDBC" 代表使用JDBC的提交和回滚来管理事务
			 
			mybatis提供了3种数据源类型,分别是:POOLED,UNPOOLED,JNDI
			POOLED 表示支持JDBC数据源连接池
			UNPOOLED 表示不支持数据源连接池
			JNDI 表示支持外部数据源连接池
			 
		    
				
				
				
				
				
                
                
			 
		 

看了mysql的驱动的源码,还是没有找到原因,但是当我将mybatis默认的连接池POOLED换成HIKARICP的连接池后,从9月6日下午18:10:02 到9月9日10点都没有再包上面的错,
更换数据源的方式请看 : https://blog.csdn.net/fhf2424045058/article/details/100558976

但是呢,在发送报文的时候又报错了:

[2019-09-09 10:02:21,558] (JdbcTransaction.java:138) DEBUG [pool-1-thread-1] jdbc.JdbcTransaction (JdbcTransaction.java:138) - Opening JDBC Connection
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
### The error may exist in com/test/send/mapper/ConsistencyWorkSpRangeMapper.xml
### The error may involve com.test.send.mapper.ConsistencyWorkSpRangeMapper.selectConsistencyWorkSpRange
### The error occurred while executing a query
### Cause: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
        at com.sun.proxy.$Proxy10.selectConsistencyWorkSpRange(Unknown Source)
        at com.test.send.dao.ConsistencyWorkSpRangeDao.selectConsistencyWorkSpRange(ConsistencyWorkSpRangeDao.java:32)
        at com.test.send.service.impl.ConsistencyWorkSpRangeServiceImpl.selectConsistencyWorkSpRange(ConsistencyWorkSpRangeServiceImpl.java:30)
        at com.test.send.sendreq.ReqResult4Json.sendJsonReqString(ReqResult4Json.java:185)
        at com.test.send.sendreq.SendJsonJob.jobStart(SendJsonJob.java:92)
        at com.test.send.JobStart$1.run(JobStart.java:26)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
        at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:676)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:190)
        at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:155)
        at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100)
        at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:140)
        at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:62)
        at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:315)
        at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:75)
        at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:61)
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
        ... 17 more
java.lang.NullPointerException
        at com.test.send.sendreq.ReqResult4Json.sendJsonReqString(ReqResult4Json.java:187)
        at com.test.send.sendreq.SendJsonJob.jobStart(SendJsonJob.java:92)
        at com.test.send.JobStart$1.run(JobStart.java:26)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

如果有遇到同样错误的同学们欢迎留言交流!

你可能感兴趣的:(mysql,java操作,tomcat)