Subscriber.stopAsync() results in RejectedExecutionException

时光毁灭记忆、已成空白 提交于 2019-12-08 17:40:36

I had the exact same issue when running similar code from a JUnit test, and found this related answer on multithreading in general, suggesting that a ThreadPool is closed while Listeners are still referring to it. I also looked into the code of Subscriber.java on GitHub, and found an example for receiving a number of messages in the JavaDoc on startAsync(), suggesting to wait for termination of stopAsync().

Try changing

subscriber.stopAsync();

to

subscriber.stopAsync().awaitTerminated();

Worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!