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