Created
August 11, 2015 15:06
-
-
Save enesakar/a1b510824ffc1e6c8a0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws ExecutionException, InterruptedException { | |
| Config cfg = new Config(); | |
| HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg); | |
| final IExecutorService ex = instance.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 { | |
| 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