Batch Job Multi threading D365FO AX7


Multi-threaded batch job



Normally, when we schedule our "Run Base Batch" class as a batch job, it will create a single task. Which will be responsible to execute the complete process in a single thread.

But, As you know like AX-2009 and AX-2012. In D365FO We can add multiple AOS servers in a single batch group and they can process multiple tasks simultaneously. 

In this demo, I will show, How to create a multi-threading Batch job.
following are the steps
Step-1 Create a table for demo purposes in our demo we keep the table name is SLD_DemoTable.





Step-2 Create a class with the name SLD_DemoBusinessLogic and write your business logic in this class.
In the demo, I write only to insert records in a table and show you guys how it works.






Reference Code

class SLD_DemoBusinessLogic
{

    public void processInit(VendTable _vend)
    {
        SLD_DemoTable   SLDDemoTable;

        SLDDemoTable.clear();
        SLDDemoTable.VendName=_vend.name();
        SLDDemoTable.VendAccount=_vend.AccountNum;
        SLDDemoTable.insert();

    }

}

Step-3 Create a batch job class with the name SLD_DemoMultiThreadTask.
This class we will use as Task in the main batch job.




Step-4 In this class We Create a getter setter to store vend table buffer;
Step-5 Create an object of our business logic class and execute the method



Reference Code

public class SLD_DemoMultiThreadTask extends RunBaseBatch
{
  
  VendTable ventTableBuffer;
    #DEFINE.CurrentVersion(1)
    #LOCALMACRO.CurrentList
        ventTableBuffer
    #ENDMACRO

        public ClassDescription caption()
       
        {
              ClassDescription ret;
          
              ret = 'Update Multiple Thread task';
          
              return ret;
          
        }

    container pack()
    {
        return [#CurrentVersion,#CurrentList];
    }

    public boolean unpack(container _packedClass)
    {
        int version = conPeek(_packedClass,1);
   
        switch (version)
        {
            case #CurrentVersion:
                [version,#CurrentList] = _packedClass;
                break;
            default:
                return false;
        }
        return true;
    }

    public void pramVendBuffer(VendTable _vend)
    {
        ventTableBuffer=_vend;
    }

    public void run()
    {
        try
        {
            SLD_DemoBusinessLogic       SLDDemoBusinessLogic=new SLD_DemoBusinessLogic();

            SLDDemoBusinessLogic.processInit(ventTableBuffer);
     
        }
        catch
        {
            info(strFmt("%1",xSession::xppCallStack()));
        }
    }

}

Step-6 Now Create the main batch job which will respond to create multiple tasks in the single batch job.




Reference Code

class SLD_DemoMultiThreadBatch extends RunBaseBatch
{
    BatchHeader                             batchHeader;

    VendTable        vendTable;
 

    public static void main(Args args)
    {
        SLD_DemoMultiThreadBatch  objMultiThread = new SLD_DemoMultiThreadBatch();

        if (objMultiThread.prompt())
        {
            objMultiThread.run();
        }
    }

    void run()
    {
        SLD_DemoMultiThreadTask                 SLDDemoMultiThreadTask;
       

        try
        {
          
            while select firstonly10 vendTable
            {
                if(this.isInBatch())
                {
                    if(!batchHeader)
                    {
                        batchHeader = BatchHeader::construct(this.parmCurrentBatch().BatchJobId);
                    }
                    batchHeader.parmCaption("Multiple thread batch jobs");
                    SLDDemoMultiThreadTask =  new SLD_DemoMultiThreadTask();
                    SLDDemoMultiThreadTask.pramVendBuffer(vendTable.data());
                    // add tasks to the batch header
                    batchHeader.addRuntimeTask(SLDDemoMultiThreadTask, this.parmCurrentBatch().RecId);
                }

                else
                {

                    // execute your code here when not running in batch
                }
            }
            if(batchHeader)
            {
                // save the batchheader with added tasks
                batchHeader.save();
            }

        }
        catch
        {
            info(strFmt("%1",xSession::xppCallStack()));
        }
    }

    public container pack()

    {

        return conNull();

    }

    public boolean unpack(container packedClass)

    {

        return true;

    }

}


Step-7 Now create an Action menu item and reference our batch job SLD_DemoMultiThreadBatch .




Step-8 Build and sync database and module and run the job.
Step-9 Navigate to your batch job page and find your job and check Job Task.






Step-10  before execution of the batch job check the demo table. 
you can check the below screenshot currently table is empty.


After execution of the job table filled with vendors' names.



Please feel free to contact me if you are facing any issues during the implementation of this blog



Support Faryal's Cusine


10 comments:

  1. Can you please provide the same logic using Sysoperation Framework in D 365 F&O

    ReplyDelete
    Replies
    1. What has your government done to help save you from your financial instability? you strive to survive and yet you hear stories of how your leaders have become terror in your entities... is time to make a different. for will have made money, and we have also come to help you out from your long time of financial suffering. clearing of credit card is made available, software for hacking ATM machines, bank to bank hacking and transfer, change your school grade and become something useful in the society. we also have other form of services such as Facebook hack, whats-app hack, twitter hack, i cloud hack, tracking of smart phones, hacking CCTV, installation of software on desktop and PC, snap-chat hack, Skype hack, wire wire, bitcoin account hack, erase your criminal record and be free for ever. database hack and many more. e-mail: cyberhackingcompany@gmail.com for your genuine hacking services and we shock we your findings.  

      Delete
    2. Dynamics 365 Finance And Operations Talk: Batch Job Multi Threading D365Fo Ax7 >>>>> Download Now

      >>>>> Download Full

      Dynamics 365 Finance And Operations Talk: Batch Job Multi Threading D365Fo Ax7 >>>>> Download LINK

      >>>>> Download Now

      Dynamics 365 Finance And Operations Talk: Batch Job Multi Threading D365Fo Ax7 >>>>> Download Full

      >>>>> Download LINK 9h

      Delete
  2. can you please provide the same logic for sysoperation frame work

    ReplyDelete
  3. INSTANT AFFORDABLE PERSONAL/BUSINESS/HOME/INVESTMENT LOAN OFFER WITHOUT COST/STRESS CONTACT US TODAY VIA Whatsapp +19292227023 Email drbenjaminfinance@gmail.com

    Hello, Do you need an urgent loan to support your business or in any purpose? we are certified and legitimate and international licensed loan Company. We offer loans to Business firms, companies and individuals at an affordable interest rate of 2% , It might be a short or long term loan or even if you have poor credit, we shall process your loan as soon as we receive your application. we are an independent financial institution. We have built up an excellent reputation over the years in providing various types of loans to thousands of our customers. We Offer guaranteed loan services of any amount to people all over the globe, we offer easy Personal loans,Commercial/business loan,Car loan Leasing/equipment finance, Debt consolidation loan, Home loan, ETC with either a good or bad credit history. If you are in need of a loan do contact us via Whatsapp +19292227023 Email drbenjaminfinance@gmail.com

    Share this to help a soul right now, Thanks

    ReplyDelete
  4. I never thought that I will be qualify for a loan that Officer Pedro and his loan company granted me which was very smooth and transparent in every conversation that we make through the loan process, I will once again thank him and his loan organization for a job well done by offering me a loan of 22 million Euro with the low rate of 2% annual return they are genuine and loan register company with simple terms and conditions.
    Contact the loan company through pedroloanss@gmail.com whatsapp: + 1-8632310632.

    ReplyDelete
  5. One evening, i was reading a blog of how so many people got this blank card online when i was trying to search for a new job, but it didn't seem clear to me so i ignored. Three days later, i was so surprised to see a comment by my cousin on how he got the blank card worth Thousand Dollars and without hesitation i gave him a call to come over to the house to tell me more about the card and he told me that its a miracle that i needed to per-take. He gave me the email address of the hackers and i contact them for the card and they responded and told me all the procedures and terms of the card which was also what my cousin told me, i agreed and completed their requirement to get the card. Four days later, i heard knock on my door an behold was the courier agent who brought the parcel to my house and today i am rich and i thank God to this hackers and to my cousin brother who lead me to them. It might sounds odd but you can get yours via email: darkwebcyberhackers@gmail.com OR darkwebcyberhackers@yahoo.com or WhatsApp: +18033921735

    ReplyDelete
  6. Are you new to stocks and cypto currency trading and want to be successful in your trade if yes then get help from the most down to earth and reliable expert trader I has been managing trading account for some time now and I can proudly say I make Good withdrawals monthly of $5000 Kindly reply back for more information on how to trade Contact via whatsapp +447883246472 email: tdameritrade077@gmail.com

    ReplyDelete
  7. Dynamics 365 Finance And Operations Talk: Batch Job Multi Threading D365Fo Ax7 >>>>> Download Now

    >>>>> Download Full

    Dynamics 365 Finance And Operations Talk: Batch Job Multi Threading D365Fo Ax7 >>>>> Download LINK

    >>>>> Download Now

    Dynamics 365 Finance And Operations Talk: Batch Job Multi Threading D365Fo Ax7 >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...