Over a million developers have joined DZone.

Multi-Node Distributed Execution Using Hazelcast and Dexecutor

DZone's Guide to

Multi-Node Distributed Execution Using Hazelcast and Dexecutor

In this post, we take a look at how to execute Dexecutor in a distributed mode using Hazelcast. Read on to find out how it's done.

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Today, we will try to execute Dexecutor in a distributed mode using Hazelcast. For the demo, we would be setting up multiple Hazelcast nodes on a single machine.

Refer to Introducing Dexecutor to get an introduction to Dexecutor and to understand the problem we'll solve in a distribute fashion. In short:

We would be distributing the execution of Dexecutor tasks on Hazelcast compute nodes in a single machine.

To do that one of the nodes would act as master and submit the tasks to Hazelcast compute nodes to be executed by other Hazelcast compute nodes using Dexecutor.

Here are the steps to do that :

Step 1: Add the Dexecutor-Hazelcast Dependency


Step 2: Get an Instance of Hazelcast IExecutorService From Hazelcast

Config cfg = new Config();
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
IExecutorService executorService = instance.getExecutorService("test");

Step 3: Create Dexecutor Using IExecutorService

if (isMaster) {
    DefaultDependentTasksExecutor<Integer, Integer> dexecutor = newTaskExecutor(executorService);

private DefaultDependentTasksExecutor<Integer, Integer> newTaskExecutor(IExecutorService executorService) {
    DependentTasksExecutorConfig<Integer, Integer> config = new DependentTasksExecutorConfig<Integer, Integer>(
    new HazelcastExecutionEngine<Integer, Integer>(executorService), new SleepyTaskProvider());
    return new DefaultDependentTasksExecutor<Integer, Integer>(config);

private static class SleepyTaskProvider implements TaskProvider<Integer, Integer> {
    public Task<Integer, Integer> provideTask(final Integer id) {
        return new HazelcastTask(id);

Step 4: Execution

Open three terminals and execute the following:

Terminal #1

mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.hazelcast.Node" -Dexec.classpathScope="test" -Dexec.args="s node-A"

Terminal #2

mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.hazelcast.Node" -Dexec.classpathScope="test" -Dexec.args="s node-B"

Terminal #3

mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexe

Here is the execution:

Here is the complete node implementation


Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 

dexecutor ,hazelcast ,java ,distributed applications

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}