Search code examples
springhazelcast

Load hazelcast imap on application startup


How can i load map in startup . I have below config in my hazelcast.xml file with inital mode eager. But still its loading only when map is first accessed.

  <map name="cpMap">
        <map-store enabled="true" initial-mode="EAGER">
            <class-name>com.hazelcast.samples.spring.data.migration.CPLoader</class-name>
        </map-store>
    </map>

ALso I have the map loader implementation beans as well. I am using spring for this.


Solution

  • The documentation is pretty clear on that:

    When getMap() is first called from any member, initialization starts depending on the value of InitialLoadMode. If it is set to EAGER, initialization starts on all partitions as soon as the map is touched, i.e., all partitions are loaded when getMap is called.

    Hence, the map should be accessed for the map to start populating itself. If you're using Spring, I'd recommend a CommandLineRunner bean to access the map and start the process.