3

Many of us are going through the optimization issues in AX 2012. In many of the cases optimization issues in process related code have no solution like we do have many other way around in reports.

Case: I had a case in which I have to perform a confirmation of multiple sales orders in AX 2012 on one button click. On confirmation of that sales order we need to perform some other 'Customized' process which is a bit lengthy process after following code practices and maximum optimizing the coding approach. So I have a question to how to handle this kind of scenario through multi threading

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
shabib raza
  • 73
  • 1
  • 5

3 Answers3

5

The Introduction to the SysOperation Framework provides concrete examples how to paralellize code in AX2012 (the examples calculate prime numbers).

Also, theres an excellent series of posts called Batch Parallelism in AX part I, II, III and IV that provides an analysis how to best match "threads" to batch tasks.

Kim Sullivan
  • 943
  • 2
  • 10
  • 15
2

I have learnt about the feature of using multi threading using Thread class in Ax2012 then i tried to implement in following way.

You first need to implement all your logic in Static method of a class. That static method should contain Thread Class as an parameter e.g

public static void process(thread _thread)
{
    FG_ConfirmationEngine   confirmationEngine = new FG_ConfirmationEngine();
    salesTable              salesTable;
    container               _con;;
    _con = _thread.getInputParm();
    info(conPeek(_thread.getInputParm(),1));
    salesTable = salesTable::find(conPeek(_thread.getInputParm(),1));
    confirmationEngine.parmSalesTable(salesTable);
    confirmationEngine.run();// in this method all of my confirmation pre and post logic exist
}

After creating that static method in a class you need to write the calling of that method. Note: You cannot send any Args, Object through Thread class. You can only send parameters in a form of container through thread.setInputParm() method like _thread.setInputParm([salestable.salesid]) method.

Calling:

salesline                   salesline;
ExecutePermission           perm;
Thread                      myThread;
ttsBegin;

perm = new ExecutePermission();

if (!perm)
return;

perm.assert();

while select salesid from salestable
    where salestable.FG_BookingReferenceID == "BRF-0001"
{
    myThread = new Thread();
    myThread.setInputParm([salestable.SalesId]);
    if (myThread)
    {
        myThread.removeOnComplete(true);
        myThread.run(classnum(FG_ConfirmationEngine), staticMethodStr(FG_ConfirmationEngine,process));
    }
}

CodeAccessPermission::revertAssert();

Hope it helps. Happy DAXing

shabib raza
  • 73
  • 1
  • 5
2

Don't use multi threading directly. It is a client technology.

Use the batch processing framework in the Axatpa. It is server technology with multi threading on a server. https://msdn.microsoft.com/en-us/library/gg243235.aspx

It mean for developer: create your class and extend it from RunBasBatch (see Tutorial_RunBaseBatch class in the AOT) or SysOperation https://msdn.microsoft.com/en-us/library/gg862488.aspx

mazzy
  • 1,025
  • 1
  • 13
  • 26