Thursday, 1 October 2015

Multithreading with Business Operation Framework [AX 2012]

In this post I will discuss the basics of multi threading with business operations framework and I will provide a sample you can work with.
Multithreading can give you a huge performance boost if you could spin each process separately. The biggest hurdle with writing a process to work via multi threading can be a little confusing and time consuming to develop. So, what I have done is create a generic xpo project which I have used many times as a starting point.
Below is a screenshot of what the net result is of my sample project.
image
The xpo contains the following project.
image

Download xpo

The \Classes\Processor\process method is the main entry method. If it is run with out the batch it will execute each record separately.
Otherwise, if it is run in batch it will bundle the records based on a default bundle size (I have set it to 10). I then use a list to store the 10 customer recIds. The reason I bundle the records is because when you multithread, you may not want to process each record separately. As there maybe an overhead in spinning up each thread.
image
Then on the task class that is receiving the bundle, breaks up the list and gets all the RecIds.
image
Credit to both Klaas Deforche and Kenny Saelen who have written a great book on services. They have also written great posts on their blog.
http://www.artofcreation.be/2010/10/03/batch-multithreading/
http://www.ksaelen.be/wordpresses/dynamicsaxblog/2012/02/business-operation-framework-and-multi-threading/

2 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Munib Ahmed said...

Fixed link