Over a million developers have joined DZone.

Take Data Migration to the Next Level Using Dexecutor

See how you can use Dexecutor to migrate your data in parallel to avoid long wait times and delays.

· Database Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database. Try it now! Brought to you in partnership with MongoDB.

Say you have a data migration process that updates your application from version X to X+1 by running migration scripts (each script consists of a sequence of instructions) sequentially to bring the application to a desired state.


The synchronous process is causing delays, leading to unproductive wait times and dissatisfaction from users. There is a need to run tasks in parallel wherever applicable to come to the desired state.

Driving Forces

The following are driving forces behind Dexecutor.

  • Supports parallel execution, conditionally may revert to sequential execution (if such logic is provided)
  • Ultra light (Version 1.1.1 is 44KB)
  • Ultra fast
  • Distributed Execution supported
  • Immediate/Scheduled Retry logic supported
  • Non-terminating behavior supported
  • Conditionally skip the task execution


Incorporate Dexecutor into your script execution logic — additionally distribute the execution using Infinispan, Hazelcast, or Ignite. Here is the sample application that demonstrates this functionality. Fork it and have fun!

Dexecutor can be used in this case easily by adding algorithmic logic on top of Dexecutor, which builds the graph based on table names. Let's assume the following scripts:

Script 1 ==> operates on Tables t1 and t2 and takes 5 minute
Script 2 ==> operates on Tables t1 and t3 and takes 5 minute
Script 3 ==> operates on Tables t2 and t4 and takes 5 minute
Script 4 ==> operates on Tables t5 and t6 and takes 5 minute
Script 5 ==> operates on Tables t5 and t7 and takes 5 minute
Script 6 ==> operates on Tables t6 and t8 and takes 5 minute

Normally these scripts are executed sequentially as follows.

Script 1  5 minutes
Script 2  5 minutes
Script 3  5 minutes
Script 4  5 minutes
Script 5  5 minutes
Script 6  5 minutes

Total time 30 minutes 

In a sequential case, your total execution time would be 30 minutes. However, if we could parallelize the script execution and make sure scripts are executed in right sequence and order, then we could save time, decreasing the total execution time to just 10 minutes.

       +----------+                       +----------+
       | Script 1 |                       | Script 4 |             ==> 5 minutes
  +----+----------+--+               +----+----------+-----+
  |                  |               |                     |
  |                  |               |                     |
+-----v----+   +-----v----+     +----v-----+        +------v---+
| Script 2 |   | Script 3 |     | Script 5 |        | Script 6 |   ==> 5 minutes
+----------+   +----------+     +----------+        +----------+

Total Time 10 minutes

Using Dexecutor, we just have to write the algorithm, which facilitates building graph using the API exposed by Dexecutor, and the rest would be taken care by Dexecutor.

MigrationTasksExecutor implements that algorithm, considering the SQL in the migration scripts. Because table names in the SQL play a crucial role in building the graph, we need an efficient, ultra light, and ultra fast library to extract table names out of the SQL, and hence, we would use sql-table-name-parser. Use it by adding the following dependency in your POM.


And of course, Dexecutor should be added as dependency as well


The graph, that would be built, considering the migration script is the following:


As can be seen here, nodes base1, base3, and base 4 run in parallel and once one of them finishes, their children are executed. For example, if node base1 is finished, then its children base2 and app3-1 are executed, and so on.

Notice that for node app2-4 to start, app1-4 and app2-1 must finish. Similarly, for node app3-2 to start, app3-1 andapp2-4 must finish.

Just run this class to see how things proceed.


We can indeed run dependent/independent tasks in easy and reliable way with Dexecutor.


Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.

dexecutor,migration,database,parallel processing

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