引文
使用原生rocketmq-client推送普通消息,把new DefaultMQProducer().send(String msg)方法抛出的异常捕获后IDEA抛出”Either re-interrupt this method or rethrow the “InterruptedException” that can be caught here.“警告;这个问题是因为org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl#sendKernelImpl()抛出的InterruptedException异常,具体是rocketmq底层使用netty框架创建Channel发送消息时,为保证消息发送失败业务不阻塞线程,可以超时失败,使用CountDownLatch.await阻塞主线程,超时则中断当前线程。
错误展示
org.apache.rocketmq.remoting.netty.NettyRemotingAbstract#invokeSyncImpl方法中responseFuture.wartResponse(timeoutMillis)方法阻塞
解决方法
1.直接向外层方法抛出InterruptedException异常
2.捕获异常catch内使用Thread.currentThread().interrupt()中断当前线程