D365 Finance & Operations and Dynamics AX Forum

 View Only

All you Need to Know about Multithreading in AX2012

By Nandita Nityanandam posted Oct 12, 2018 08:11 AM

  

Multithreading is a feature that allows simultaneous execution of any two or more processes or threads by maxing out the CPU. If you try to carry out an extensive task without threading, it will take a long time and can cause the screen to go into a non-responsive state. Although the batch job functionality allows you to run the process in the background, it tends to have some limitations. For example, you cannot read an Excel file from a batch. However, with threading, the process runs in the background, allowing you to simultaneously carry out other AX activities – you can read Excel data and perform business logic in the background. Please note that since threads run on client machines and not on the server, threading is only useful when there is capacity to use batch-process or SysOperationFramework.

Enabling Multithreading in AX 2012

In AX2012, multithreading is a very useful feature. To make the most of the feature, you can divide any process into different tasks, and run them in parallel. You need to assign each task with different threads so that multiple threads do not have to wait for each other to execute, they run simultaneously. Here’s how you can enable multithreading in AX 2012:

Create a class DemoThread.

MultithreadingAX1.png

Create a method ‘ProcessBusinessLogic’. Ensure that the method is static as this will run in the Thread.

MultithreadingAX2.png

In the main method, create an object of Thread class, Thread firstThread = new Thread();

To pass the argument, you need to use ‘setInputParm’ method of standard thread class, which accepts the container data.

firstThread.setInputParm(['Param1','Param2','Param3']);

You then need to call run method of the thread class to assign a task to the thread. In the first argument, pass the class name and in the second, the static method name which you want to execute in the Thread.

firstThread.run(classNum(DemoThread),staticMethodStr(DemoThread,ProcessBusinessLogic);

MultithreadingAX3.png

Now create another static method ‘ProcessBusinessLogicTask2’ to execute it in another thread simultaneously with the other task.

MultithreadingAX4.png
In the main method, create another object of the Thread class and then assign the task to this thread object to achieve multithreading.

secondThread = new Thread();

secondThread.run(classNum(DemoThread),staticMethodStr(DemoThread,processBusinessLogicTask2));

You will be able to see that the firstThread and secondThread run simultaneously.

MultithreadingAX5.png

Improve Efficiency

In a world where fast and timely execution of processes is imperative, concurrent activity through multithreading goes a long way. By fully exploiting the multithreading feature in AX 2012, there’s a lot you can achieve: from improved application throughput, simultaneous and full use of multiple processors, superior application responsiveness and performance, better resource utilization, improved process-to-process communication, and simplifying the structure of complex applications – enable multithreading and improve the efficiency of your business.


Angna_Thakkar.jpg

About the Author - Angna Thakkar

Angna Thakkar is a competent Senior Project Manager, Microsoft Dynamics AX Technical at Indusa with over 10 years of experience in managing multi-disciplinary teams of varying sizes and complex programs of work. She is always committed to professionalism, highly organized, able to see the big picture while paying attention to small details.

Contributing Author: Malavika Nityanandam

0 comments
43 views

Permalink