MessageArrived MQTT paho 库

MessageArrived MQTT paho library

大家好,我是初学者,我正在尝试实现 paho 库,我的 paho 客户端在 messageArrived 中收到关于特定主题的消息,我读到 messageArrived 函数是同步的,意味着一次一个?正确的 !

问题是我的 tomcat 有时会停止,我必须重新启动它,然后我看到一个登录 catalina.err

The web application [] is still processing a request that has yet to finish. This is very likely to create a memory leak. You can control the time allowed for requests to finish by using the unloadDelay attribute of the standard Context implementation.

而且我的过程有点长,我想是因为我必须根据我的要求检查消息,我还尝试用相同的功能与他们一起创建一些警报短信,所以这可能需要一些时间。

那么我应该如何管理它,对吗?还是完全猜错了??

任何建议都会很棒。

处理使用 MQTT 消息的长 运行 任务的正确方法是创建一个线程池,然后将这些消息的处理从 onMessageArrived() 方法传递给线程池。

java.util.concurrent.ThreadPoolExecutor 可能是您最好的起点。