title: Starting 2 hazelcast instances synchronously on a single machine (with hazelcast.initial.min.cluster.size=2)
body: <p>How can I configure Hazelcast (optimally the version I currently use: 3.1.2) to run 2 hazelcast instances on a single machine, and block the first instance during startup until both instances are present?</p>
  
  <h2> hazelcast.initial.min.cluster.size </h2>
  
  <p>The blocking behavior described above can be implemented with the help of <code>hazelcast.initial.min.cluster.size</code> when running both instances on different machines: With the configuration: </p>
  
  <pre><code>Config cfg = new Config(); 
  cfg.setProperty("hazelcast.initial.min.cluster.size",
    Integer.toString(minimumInitialMembersInHazelCluster));
  cfg.getGroupConfig().setName(clusterName);
  hazelInst = Hazelcast.newHazelcastInstance(cfg);
  </code></pre>
  
  <p>run on different machines, I get the output</p>
  
  <pre><code>Apr 15, 2014 9:31:39 AM com.hazelcast.instance.DefaultAddressPicker
  INFO: Prefer IPv4 stack is true.
  Apr 15, 2014 9:31:39 AM com.hazelcast.instance.DefaultAddressPicker
  INFO: Picked Address[192.168.31.105]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
  Apr 15, 2014 9:31:40 AM com.hazelcast.system
  INFO: [192.168.31.105]:5701 [dev] Hazelcast Community Edition 3.1.2 (20131120) starting at Address[192.168.31.105]:5701
  Apr 15, 2014 9:31:40 AM com.hazelcast.system
  INFO: [192.168.31.105]:5701 [dev] Copyright (C) 2008-2013 Hazelcast.com
  Apr 15, 2014 9:31:40 AM com.hazelcast.instance.Node
  INFO: [192.168.31.105]:5701 [dev] Creating MulticastJoiner
  Apr 15, 2014 9:31:40 AM com.hazelcast.core.LifecycleService
  INFO: [192.168.31.105]:5701 [dev] Address[192.168.31.105]:5701 is STARTING
  Apr 15, 2014 9:31:43 AM com.hazelcast.cluster.MulticastJoiner
  INFO: [192.168.31.105]:5701 [dev] 
  
  
  Members [1] {
      Member [192.168.31.105]:5701 this
  }
  
  Apr 15, 2014 9:31:43 AM com.hazelcast.core.LifecycleService
  INFO: [192.168.31.105]:5701 [dev] Address[192.168.31.105]:5701 is STARTED
  Apr 15, 2014 9:31:43 AM HazelMultiInstanceExp &lt;init&gt;
  SEVERE: debug: joined via JoinConfig{multicastConfig=MulticastConfig [enabled=true, multicastGroup=224.2.2.3, multicastPort=54327, multicastTimeToLive=32, multicastTimeoutSeconds=2, trustedInterfaces=[]], tcpIpConfig=TcpIpConfig [enabled=false, connectionTimeoutSeconds=5, members=[], requiredMember=null], awsConfig=AwsConfig{enabled=false, region='us-east-1', securityGroupName='null', tagKey='null', tagValue='null', hostHeader='ec2.amazonaws.com', connectionTimeoutSeconds=5}} with 1 members.
  Apr 15, 2014 9:31:43 AM com.hazelcast.instance.DefaultAddressPicker
  INFO: Prefer IPv4 stack is true.
  Apr 15, 2014 9:31:43 AM com.hazelcast.instance.DefaultAddressPicker
  INFO: Picked Address[192.168.31.105]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5702], bind any local is true
  Apr 15, 2014 9:31:43 AM com.hazelcast.system
  INFO: [192.168.31.105]:5702 [dev] Hazelcast Community Edition 3.1.2 (20131120) starting at Address[192.168.31.105]:5702
  Apr 15, 2014 9:31:43 AM com.hazelcast.system
  INFO: [192.168.31.105]:5702 [dev] Copyright (C) 2008-2013 Hazelcast.com
  Apr 15, 2014 9:31:43 AM com.hazelcast.instance.Node
  INFO: [192.168.31.105]:5702 [dev] Creating MulticastJoiner
  Apr 15, 2014 9:31:43 AM com.hazelcast.core.LifecycleService
  INFO: [192.168.31.105]:5702 [dev] Address[192.168.31.105]:5702 is STARTING
  Apr 15, 2014 9:31:43 AM com.hazelcast.nio.SocketConnector
  INFO: [192.168.31.105]:5702 [dev] Connecting to /192.168.31.105:5701, timeout: 0, bind-any: true
  Apr 15, 2014 9:31:43 AM com.hazelcast.nio.SocketAcceptor
  INFO: [192.168.31.105]:5701 [dev] Accepting socket connection from /192.168.31.105:60803
  Apr 15, 2014 9:31:43 AM com.hazelcast.nio.TcpIpConnectionManager
  INFO: [192.168.31.105]:5702 [dev] 60803 accepted socket connection from /192.168.31.105:5701
  Apr 15, 2014 9:31:43 AM com.hazelcast.nio.TcpIpConnectionManager
  INFO: [192.168.31.105]:5701 [dev] 5701 accepted socket connection from /192.168.31.105:60803
  Apr 15, 2014 9:31:49 AM com.hazelcast.cluster.ClusterService
  INFO: [192.168.31.105]:5702 [dev] 
  
  Members [2] {
      Member [192.168.31.105]:5701
      Member [192.168.31.105]:5702 this
  }
  </code></pre>
  
  <p>but run with two instances on one machine, I get </p>
  
  <pre><code>Apr 15, 2014 9:25:14 AM com.hazelcast.instance.DefaultAddressPicker
  INFO: Prefer IPv4 stack is true.
  Apr 15, 2014 9:25:14 AM com.hazelcast.instance.DefaultAddressPicker
  INFO: Picked Address[192.168.31.105]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
  Apr 15, 2014 9:25:15 AM com.hazelcast.system
  INFO: [192.168.31.105]:5701 [test3] Hazelcast Community Edition 3.1.2 (20131120) starting at Address[192.168.31.105]:5701
  Apr 15, 2014 9:25:15 AM com.hazelcast.system
  INFO: [192.168.31.105]:5701 [test3] Copyright (C) 2008-2013 Hazelcast.com
  Apr 15, 2014 9:25:15 AM com.hazelcast.instance.Node
  INFO: [192.168.31.105]:5701 [test3] Creating MulticastJoiner
  Apr 15, 2014 9:25:15 AM com.hazelcast.core.LifecycleService
  INFO: [192.168.31.105]:5701 [test3] Address[192.168.31.105]:5701 is STARTING
  Apr 15, 2014 9:25:18 AM com.hazelcast.cluster.MulticastJoiner
  INFO: [192.168.31.105]:5701 [test3] 
  
  
  Members [1] {
      Member [192.168.31.105]:5701 this
  }
  
  Apr 15, 2014 9:25:18 AM com.hazelcast.instance.HazelcastInstanceImpl
  INFO: [192.168.31.105]:5701 [test3] HazelcastInstance waiting for cluster size of 2
  </code></pre>
  
  <p>with the last INFO message repeated ad infinitum.</p>
  
  <p>So the cluster size is the number of nodes in the cluster, not the number of hazelcast instances? </p>
  
  <h2> Blocking behavior on a single machine </h2>
  
  <p>I use <code>cfg.setProperty("hazelcast.initial.min.cluster.size","2")</code> so the two distributed instances start my distributed algorithm synchronously. Furthermore, it solves the problem that some hazelcast members are not found, see <a href="https://stackoverflow.com/a/20716919/750378">https://stackoverflow.com/a/20716919/750378</a>. </p>
  
  <p>So how do I avoid both problems when running on a single machine? It would be great if the cluster size would simple be the number of running hazelcast instances. Then I could keep my configuration above no matter how I deploy my two instances (on 1 or 2 machines).  </p>
  
  <h2> Update </h2>
  
  <p>I have posted an issue about the cluster size at <a href="https://github.com/hazelcast/hazelcast/issues/2292" rel="nofollow noreferrer">https://github.com/hazelcast/hazelcast/issues/2292</a>.</p>