首先我怀疑是不是获取到连接时直接就失效了.
版本
druid: 1.0.26
mysql: 5.1.44
配置
DruidDataSource dataSource = new DruidDataSource();
dataSource.setInitialSize(5);
dataSource.setMinIdle(5);
dataSource.setMaxWait(60000);
dataSource.setValidationQuery("select 1");
dataSource.setMaxActive(30);
dataSource.setTestWhileIdle(true);
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setRemoveAbandoned(true);
dataSource.setTimeBetweenEvictionRunsMillis(60000);
dataSource.setMinEvictableIdleTimeMillis(300000);
dataSource.setPoolPreparedStatements(true);
dataSource.setMaxPoolPreparedStatementPerConnectionSize(20);
String connectionInitSqls = "SET NAMES utf8mb4";
StringTokenizer tokenizer = new StringTokenizer(connectionInitSqls, ";");
dataSource.setConnectionInitSqls(Collections.list(tokenizer));
return dataSource;
异常
20200804110545|0000016003|ERROR||2020-08-04 11:05:45.767 Druid-ConnectionPool-Destroy-249515830 DruidDataSource 1243 - discard connection com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during rollback(). Transaction resolution unknown.##
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:425)##
at com.mysql.jdbc.Util.getInstance(Util.java:408)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)##
at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4584)##
at com.alibaba.druid.pool.DruidPooledConnection.rollback(DruidPooledConnection.java:757)##
at com.alibaba.druid.pool.DruidDataSource.recycle(DruidDataSource.java:1293)##
at com.alibaba.druid.pool.DruidPooledConnection.recycle(DruidPooledConnection.java:305)##
at com.alibaba.druid.pool.DruidPooledConnection.syncClose(DruidPooledConnection.java:284)##
at com.alibaba.druid.pool.DruidPooledConnection.close(DruidPooledConnection.java:241)##
at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:85)##
at com.alibaba.druid.pool.DruidDataSource.removeAbandoned(DruidDataSource.java:2160)##
at com.alibaba.druid.pool.DruidDataSource$DestroyTask.run(DruidDataSource.java:2095)##
at com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:2079)
20200804110545|0000016003|ERROR||2020-08-04 11:05:45.768 Druid-ConnectionPool-Destroy-249515830 DruidDataSource 1358 - recyle error com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during rollback(). Transaction resolution unknown.##
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:425)##
at com.mysql.jdbc.Util.getInstance(Util.java:408)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)##
at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4584)##
at com.alibaba.druid.pool.DruidPooledConnection.rollback(DruidPooledConnection.java:757)##
at com.alibaba.druid.pool.DruidDataSource.recycle(DruidDataSource.java:1293)##
at com.alibaba.druid.pool.DruidPooledConnection.recycle(DruidPooledConnection.java:305)##
at com.alibaba.druid.pool.DruidPooledConnection.syncClose(DruidPooledConnection.java:284)##
at com.alibaba.druid.pool.DruidPooledConnection.close(DruidPooledConnection.java:241)##
at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:85)##
at com.alibaba.druid.pool.DruidDataSource.removeAbandoned(DruidDataSource.java:2160)##
at com.alibaba.druid.pool.DruidDataSource$DestroyTask.run(DruidDataSource.java:2095)##
at com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:2079)
20200804110545|0000016003|ERROR||2020-08-04 11:05:45.768 org.springframework.kafka.KafkaListenerEndpointContainer#4-0-L-7 DruidDataSource 1243 - discard connection com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.##
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:425)##
at com.mysql.jdbc.Util.getInstance(Util.java:408)## at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)##
at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1552)##
at com.alibaba.druid.pool.DruidPooledConnection.commit(DruidPooledConnection.java:731)##
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:313)##
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)##
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)##
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)##
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)## at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)##
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)##
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)##
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)##
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)##
at com.migu.pinkstone.kafka.AccountRecordConsumer$$EnhancerBySpringCGLIB$$18bdc389.consumer(<generated>)##
at sun.reflect.GeneratedMethodAccessor252.invoke(Unknown Source)##
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)##
at java.lang.reflect.Method.invoke(Method.java:498)##
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:180)##
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:112)##
at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48)##
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:174)## at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:118)##
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:56)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchListener(KafkaMessageListenerContainer.java:751)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:735)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.access$2200(KafkaMessageListenerContainer.java:245)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer$ListenerInvoker.run(KafkaMessageListenerContainer.java:1031)##
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)##
at java.util.concurrent.FutureTask.run(FutureTask.java:266)##
at java.lang.Thread.run(Thread.java:748)
20200804110545|0000016003|ERROR||2020-08-04 11:05:45.769 org.springframework.kafka.KafkaListenerEndpointContainer#4-0-L-7 BatchLoggingErrorHandler 43 - Error while processing:
ConsumerRecord(topic = ucAccountRecord, partition = 7, offset = 1305348, CreateTime = 1596481545185, checksum = 899185602, serialized key size = 14, serialized value size = 240, key = 013U1314174669, value = {"accountName":"15253059362","createTime":"20200804030545","isDelete":0,"accountType":"0","opType":2,"md":"register","isProcessed":1,"updateTime":"20200804030545","userId":"013U1314174669","transactionId":"11e72054d6154ad493ff583ef613378f"}) org.springframework.kafka.listener.ListenerExecutionFailedException: Listener method 'public void com.migu.pinkstone.kafka.AccountRecordConsumer.consumer(java.util.List<org.apache.kafka.clients.consumer.ConsumerRecord<java.lang.String, java.lang.String>>,org.springframework.kafka.support.Acknowledgment)' threw exception; nested exception is 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.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:188)##
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:118)##
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:56)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchListener(KafkaMessageListenerContainer.java:751)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:735)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.access$2200(KafkaMessageListenerContainer.java:245)##
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer$ListenerInvoker.run(KafkaMessageListenerContainer.java:1031)##
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)##
at java.util.concurrent.FutureTask.run(FutureTask.java:266)##
at java.lang.Thread.run(Thread.java:748)##
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:316)##
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)##
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)##
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)##
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)##
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)##
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)##
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)##
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)##
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)##
at com.migu.pinkstone.kafka.AccountRecordConsumer$$EnhancerBySpringCGLIB$$18bdc389.consumer(<generated>)##
at sun.reflect.GeneratedMethodAccessor252.invoke(Unknown Source)##
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)##
at java.lang.reflect.Method.invoke(Method.java:498)##
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:180)##
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:112)##
at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48)##
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:174)## ... 9 more##
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.##
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:425)##
at com.mysql.jdbc.Util.getInstance(Util.java:408)## at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)##
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)##
at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1552)##
at com.alibaba.druid.pool.DruidPooledConnection.commit(DruidPooledConnection.java:731)##
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:313)## ... 26 more
堆栈
执行线程
"org.springframework.kafka.KafkaListenerEndpointContainer#4-0-L-7" #151 prio=5 os_prio=0 tid=0x00007fbd58033800 nid=0x67b runnable [0x00007fbcda9ea000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:101)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:174)
- locked <0x00000000870c0858> (a com.mysql.jdbc.util.ReadAheadInputStream)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3008)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3469)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3459)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3900)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2370)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2736)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
- locked <0x00000000870b7690> (a com.mysql.jdbc.JDBC4Connection)
at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1548)
- locked <0x00000000870b7690> (a com.mysql.jdbc.JDBC4Connection)
at com.alibaba.druid.pool.DruidPooledConnection.commit(DruidPooledConnection.java:731)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:313)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.migu.pinkstone.kafka.AccountRecordConsumer$$EnhancerBySpringCGLIB$$18bdc389.consumer(<generated>)
at sun.reflect.GeneratedMethodAccessor252.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:180)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:112)
at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48)
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:174)
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:118)
at org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:56)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchListener(KafkaMessageListenerContainer.java:751)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:735)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.access$2200(KafkaMessageListenerContainer.java:245)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer$ListenerInvoker.run(KafkaMessageListenerContainer.java:1031)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers:
- None
block 线程
"Druid-ConnectionPool-Destroy-249515830" #106 daemon prio=5 os_prio=0 tid=0x00007fbda08c9000 nid=0x7a waiting for monitor entry [0x00007fbcdaaeb000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4546)
- waiting to lock <0x00000000870b7690> (a com.mysql.jdbc.JDBC4Connection)
at com.alibaba.druid.pool.DruidPooledConnection.rollback(DruidPooledConnection.java:757)
at com.alibaba.druid.pool.DruidDataSource.recycle(DruidDataSource.java:1293)
at com.alibaba.druid.pool.DruidPooledConnection.recycle(DruidPooledConnection.java:305)
at com.alibaba.druid.pool.DruidPooledConnection.syncClose(DruidPooledConnection.java:284)
- locked <0x000000008a5f8810> (a com.alibaba.druid.pool.DruidPooledConnection)
at com.alibaba.druid.pool.DruidPooledConnection.close(DruidPooledConnection.java:241)
at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:85)
at com.alibaba.druid.pool.DruidDataSource.removeAbandoned(DruidDataSource.java:2160)
at com.alibaba.druid.pool.DruidDataSource$DestroyTask.run(DruidDataSource.java:2095)
at com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:2079)
Locked ownable synchronizers:
- None
它们用的同一把锁 <0x00000000870b7690> (a com.mysql.jdbc.JDBC4Connection)
导致连接无法回收, 直到满八个小时才被回收.
有什么建议不?谢谢。
1条答案
按热度按时间2skhul331#
大佬,这个问题解决了吗?