So far, most of the extra configurations that we applied have been done either by customizing the hazelcast.xml
file, or retrospectively modifying a collection in the code. However, what if we want to programmatically configure Hazelcast without the race condition that we discovered earlier? Fortunately, there is a way. By creating an instance of the Config
class, we can configure the appropriate behavior on it by using a hierarchy that is similar to the XML configuration, but in code. Before passing this configuration object over to the instance creation method, the previous example can be reconfigured to do so, as follows:
public static void main(String[] args) { Config conf = new Config(); conf.addListenerConfig( new EntryListenerConfig(new MapEntryListener(), false, true)); HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);