Running once, running everywhere
So far, we've seen how we can gain access to a distributed executor service and submit our own tasks to it for execution. However, we might need a little more control as to where a task runs. Should we want to pin a particular task to a specific node, we can use the IExecutorService
interface to provide a more flexible control over the task manager so that it can detect and control which node the task is delegated to. You can find the details of the members in the cluster from the Cluster
class, which is accessible from the HazelcastInstance
class, as follows:
Config conf = new Config(); HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf); Member thisMember = hz.getCluster().getLocalMember(); Set<Member> clusterMembers = hz.getCluster().getMembers(); IExecutorService exec = hz.getExecutorService("exec"); Callable<String> timeTask = new TimeInstanceAwareCallable(); Member member = <target member>; Future<String...