Over a million developers have joined DZone.

Introducing Dexecutor

How to use dexecutor to model your requirements in terms of object-oriented graphs in order to define execution order.

· Java Zone

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

From the dexecutor website:

Executing dependent/independent tasks in a reliable way is made so easy that even grandma can do it.

That is indeed true with dexecutor, especially considering the complexity involved in writing error-free programs that use dependent and independent tasks. Without dexecutor, you would end up writing tons of plumbing code rather than concentrating on the business requirements.

With dexecutor, you model your requirements in terms of graphs in an object-oriented way. The rest is taken care of by the framework in a reliable way. Dynamically built graphs define the execution order. For example if the following graph is built:


Then it means, task#1, task#12, and task#11 would run in parallel. Once one of them finishes their execution, its child nodes would begin their executions. For example, lets say if task#1 finishes, then task#2 and task#3 would begin, similarly with task#12 and task#11, until all the tasks are executed or if a task ends up in an error (if the execution behavior is terminating).

That’s great indeed, but how it is done ?

DefaultDependentTasksExecutor<Integer, Integer> executor = newTaskExecutor();

//Build the graph
executor.addDependency(1, 2);
executor.addDependency(1, 3);
executor.addDependency(3, 4);
executor.addDependency(3, 5);
executor.addDependency(3, 6);
//executor.addDependency(10, 2); // cycle
executor.addDependency(2, 7);
executor.addDependency(2, 9);
executor.addDependency(2, 8);
executor.addDependency(9, 10);
executor.addDependency(12, 13);
executor.addDependency(13, 4);
executor.addDependency(13, 14);

// Execute

Above code shows, dexecutor expose two kind of APIs:

  • An API to construct the graph (addDependency, addIndependent)
  • An API to start execution (execute)

That’s simple indeed, you may be wondering, how the tasks are mapped?

TaskProvider to the rescue. TaskProvider maps a graph node to a task, and does this when a Dexecutor instance is created. Refer to the Java doc for dexecutor implementation, and for an example of how to do it.

Well, the example is very simple, so can we get any real-time examples of how dexecutor can be used?

Yes indeed, dexecutor does have a sample application which provides a real time scenario, refer to it for more details.

Finally I would like to quote the features of dexecutor, here is a snapshot from the website:



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.


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 }}