Skip to content

Instantly share code, notes, and snippets.

@enesakar
Created August 11, 2015 15:10
Show Gist options
  • Select an option

  • Save enesakar/912960dcf87b5138aebd to your computer and use it in GitHub Desktop.

Select an option

Save enesakar/912960dcf87b5138aebd to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws ExecutionException, InterruptedException {
Config cfg = new Config();
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
HazelcastInstance client= HazelcastClient.newHazelcastClient();
final IExecutorService ex = client.getExecutorService("ex");
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
Map<Member, Future<String>> futureMap = ex.submitToAllMembers(new GetInstanceNameCallable());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
Thread.sleep(5000);
HazelcastInstance instance2 = Hazelcast.newHazelcastInstance(cfg);
Thread.sleep(5000);
HazelcastInstance instance3 = Hazelcast.newHazelcastInstance(cfg);
Thread.sleep(25000);
}
static class GetInstanceNameCallable implements HazelcastInstanceAware, Callable<String>, Serializable {
transient HazelcastInstance instance;
@Override
public String call() throws Exception {
System.out.println(instance.getName());
return instance.getName();
}
@Override
public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
this.instance = hazelcastInstance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment