Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果没有其他消息发送到服务,我需要实现一个心跳机制,每 X 秒向外部服务发送一个“触摸”消息以保持会话活动。我已经研究过使用诸如 ScheduledExecutorService 或 Timer 之类的东西,但我需要找到一些可以在会话上发送其他消息时重置计时器/延迟的东西,这样我就不会在不需要时发送心跳。
这种类型的心跳机制是否有任何已知的框架,因为它看起来像是常规的心跳功能?或者,谁能指出我正确的方向,以基于标准组件为我的问题创建一个有效的解决方案?
我能看到的最简单的方法就是自己编写。创建一个可以发送“触摸”消息的对象,然后创建一个守护进程来持续执行此操作。
所有这些都应该通过 POJO 和ThreadandProcess类来实现。祝你好运!
Thread
Process