Chapter 29. Distributed Execution
ExecutorServiceinterface. Tasks submitted for execution are executed on an entire cluster of JBoss Data Grid nodes, rather than being executed in a local JVM.
DistributedExecutorServiceis bound to a single cache. Tasks submitted have access to key/value pairs from that particular cache if the task submitted is an instance of
DistributedCallablesubmitted must be either
Externalizable, in order to prevent task migration to other nodes each time one of these tasks is performed. The value returned from a
Callablemust also be
29.1. Distributed Executor Service
DistributedExecutorServicecontrols the execution of
DistributedCallable, and other
Runnable, classes on the cluster. These instances are tied to a specific cache that is passed in upon instantiation:
DistributedExecutorService des = new DefaultExecutorService(cache);
DistributedTaskagainst a subset of keys if
DistributedCallableis extended, as discussed in Section 29.2, “DistributedCallable API”. If a task is submitted in this manner to a single node, then JBoss Data Grid will locate the nodes containing the indicated keys, migrate the
DistributedCallableto this node, and return a
CompletableFuture. Alternatively, if a task is submitted to all available nodes in this manner then only the nodes containing the indicated keys will receive the task.
DistributedTaskhas been created it may be submitted to the cluster using any of the below methods:
- The task can be submitted to all available nodes and key/value pairs on the cluster using the
submitEverywheremethod can also take a set of keys as an argument. Passing in keys in this manner will submit the task only to available nodes that contain the indicated keys:
- If a key is specified, then the task will be executed on a single node that contains at least one of the specified keys. Any keys not present locally will be retrieved from the cluster. This version of the
submitmethod accepts one or more keys to be operated on, as seen in the following examples:
des.submit(task, $KEY) des.submit(task, $KEY1, $KEY2, $KEY3)
- A specific node can be instructed to execute the task by passing the node's
submitmethod. The below will only be executed on the cluster's
NoteBy default tasks are automatically balanced, and there is typically no need to indicate a specific node to execute against.