Executor Service

❗️

This is a legacy Apache Ignite documentation

The new documentation is hosted here: https://ignite.apache.org/docs/latest/

IgniteCompute provides a convenient API for executing computations on the cluster. However, you can also work directly with the standard ExecutorService interface from JDK. Ignite provides a cluster-enabled implementation of ExecutorService and automatically executes all the computations in a load-balanced fashion within the cluster. Your computations also become fault-tolerant and are guaranteed to execute as long as there is at least one node left. You can think of it as a distributed cluster-enabled thread pool.

// Get cluster-enabled executor service.
ExecutorService exec = ignite.executorService();
 
// Iterate through all words in the sentence and create jobs.
for (final String word : "Print words using runnable".split(" ")) {
  // Execute runnable on some node.
  exec.submit(new IgniteRunnable() {
    @Override public void run() {
      System.out.println(">>> Printing '" + word + "' on this node from grid job.");
    }
  });
}

You can also limit the job execution to some subset of nodes from your grid:

// Cluster group for nodes where the attribute 'worker' is defined.
ClusterGroup workerGrp = ignite.cluster().forAttribute("ROLE", "worker");

// Get cluster-enabled executor service for the above cluster group.
ExecutorService exec = ignite.executorService(workerGrp);