Over a million developers have joined DZone.

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

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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


Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

dexecutor ,hazelcast ,java ,distributed applications

Published at DZone with permission of Mohammad Nadeem, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}