在节点启动时创建并填充 Hazelcast 映射

Create and populate Hazelcast map on node startup

有没有办法在节点启动后在 hazelcast(3.4 版)节点上执行代码片段?

想法是:一旦 hazelcast 节点之一开始创建地图(不等待 .getMap 在客户端执行)并从数据库中填充数据,这样当客户端请求数据时,地图已经填充.

是的。您需要为 IMap 实现 MapLoader,然后使用 MapLoader.loadAllKeys() 方法用热键初始化地图。

文档是这么说的:

You can use the MapLoader.loadAllKeys API to pre-populate the in-memory map when the map is first touched/used. If MapLoader.loadAllKeys returns NULL then nothing will be loaded. Your MapLoader.loadAllKeys implementation can return all or some of the keys. For example, you may select and return only the hot keys. MapLoader.loadAllKeys is the fastest way of pre-populating the map since Hazelcast will optimize the loading process by having each node loading its owned portion of the entries.

3.5 Map Persistence Documentation Link

这可以通过在hazelcast.xml中定义自定义服务来解决。服务构造函数在节点启动时被调用,从那里可以请求和填充 hazelcast 映射。 但是getMap的调用应该在new Thread

中完成