Reputation: 3807
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.
Upvotes: 0
Views: 903
Reputation: 3250
You can call a map after application ready or any Spring context change event via Spring's EventListener as follow.
@EventListener(ApplicationReadyEvent.class)
public void myAppReadyMethod() {
// Call any map
hz.getMap("myMap"); // Assumed hazelcast instance is already injected
}
You may take a look, Spring application javadocs, context events javadocs.
Upvotes: 1
Reputation: 1186
The documentation is pretty clear on that:
When
getMap()
is first called from any member, initialization starts depending on the value ofInitialLoadMode
. If it is set toEAGER
, initialization starts on all partitions as soon as the map is touched, i.e., all partitions are loaded whengetMap
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.
Upvotes: 1