Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

multi threading batch giving error

(0) ShareShare
ReportReport
Posted on by 437

I am facing  issue in  multi-threading and it is giving following

multi.png

Actually here I am creating multiple packing slip  for a single PO based on the delivery notes in the staging table and getting the above error message

 

Before I have checked with the technical team and  found that  in purchtable properties-> OCC  was yes  and changed in to No  and table locking was not there in multi threading  but  it created  some issue in  normal PO creation

 

So now it has been reverted back to yes and my multi-threading batch is throwing the old error message.

 

I would to invite the team members to express their thought  in this issue so that both thing can work simultaneously.

 

Thanks,

Rohit

*This post is locked for comments

  • enricoariel Profile Picture
    60 on at
    RE: multi threading batch giving error

    I'm not sure if it will fix the issue, but in the run method can you try to comment the select line and replace it with the following

    //select pessimisticLock PurchTableloc  where PurchTableloc.PurchId == purchTable.PurchId;

           PurchTableloc.setTmp();

           buf2Buf(PurchTable::find(purchTable.PurchId), PurchTableloc);

           PurchTableloc.doInsert();

    SON_PalettiPOPackMultithread::ElmoPopackingnew(PurchTableloc,deliveryNote);

  • enricoariel Profile Picture
    60 on at
    RE: multi threading batch giving error

    Hi, the reason is very simple, you have a while inside a transaction. look at the article I pointed you: it says

    ttsBegin;

    while select forUpdate myTable

    {

       myTable.MyField = 'something';

       myTable.update();

    }

    ttsCommit;

    potentially locks a large amount of records.

    that is what happens to you. besides other implication that it might have in production to other processes that might start failing because of these locks obviously if you do it in a multi thread it fails unless you lock the table with pessimistic concurrency, but that is certainly not a good idea.

    i will try to rewrite the logic of this method and post it later

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at
    RE: multi threading batch giving error

    Rohit,

    Create dependency tasks so that it doesn't create packing slips for same PO in parallel. Task should wait for one packing slip to be created on a PO before it can start to create another packing slip on same PO.

    OR

    Lock purchase order (PurchTable) so parallel tasks are waiting for lock to be released from task that has locked it first. I am not seeing ttsbegin at the beginning of the process to lock PurchTable in run method. do ttsbegin and select frupdate purchtable or purchtable.selectforupdate(true)

  • rohit1900 Profile Picture
    437 on at
    RE: multi threading batch giving error

    2248.multi-thread-PO-packing-slip.txtrun-method.txt

    I have added the below code in there also 

      _purchtable.concurrencyModel();

    and 

    select pessimisticLock PurchTableloc where PurchTableloc.PurchId == purchTable.PurchId;
    SON_PalettiPOPackMultithread::ElmoPopackingnew(PurchTableloc,deliveryNote);
    //SON_PalettiPOPackMultithread::ElmoPopackingnew(purchTable,deliveryNote);

    after making those changes I have generated IL  but still getting those errors.

    but still getting  same error after changing I am incrementing IL.

  • rohit1900 Profile Picture
    437 on at
    RE: multi threading batch giving error

    you are right that  same PO it is trying to access in the different thread  and trying to create product receipt I have discussed  and introduced sleep(3000) before retry  in the catch but still I am getting the error.

  • rohit1900 Profile Picture
    437 on at
    RE: multi threading batch giving error

    multi-thread-PO-packing-slip.txtmulti-thread-PO-packing-slip.txt

    sorry for the wrong formatting above thread i have pasted by code in the notepad and attached here ,  in the first   run method I am calling multiple delivery note(product receipt) for a single PO.

  • rohit1900 Profile Picture
    437 on at
    RE: multi threading batch giving error

    /// /// Contains the code that does the actual job of the class. /// public void run() { #OCCRetryCount SON_PalettiSummaryInvoice SON_PalettiSummaryInvoice; AifInfoLog aifInfoLog = new AifInfoLog(); PurchId lastpurchid; exceptionID = ''; try { SON_PalettiPOPackMultithread::ElmoPopackingnew(purchTable,deliveryNote); purchTable.reread(); if(purchTable.PurchStatus == PurchStatus::Received) { ttsBegin; select firstonly forUpdate PurchStatus from SON_PalettiSummaryInvoice where SON_PalettiSummaryInvoice.InvoiceNumber == purchTable.SON_SummaryInvoiceNo; SON_PalettiSummaryInvoice.PurchStatus = purchTable.PurchStatus; SON_PalettiSummaryInvoice.doUpdate(); ttsCommit; } } catch(Exception::Error) { this.geterror(aifInfoLog); info(strFmt("packing slip cancelled for the delivery note %1",deliveryNote)); } catch (Exception::Deadlock) { retry; } catch (Exception::UpdateConflict) { if (appl.ttsLevel() == 0) { if (xSession::currentRetryCount() >= #RetryNum) { throw Exception::UpdateConflictNotRecovered; } else { retry; } } else { throw Exception::UpdateConflict; } } }

  • enricoariel Profile Picture
    60 on at
    RE: multi threading batch giving error

    Without looking at your code I can only guess that maybe it has to do with the way you select records. in a multi thread  it might be updating the same record simultaneously multiple times thus failing all threads. that could be the reason why when you set the table locking to pessimistic lock it worked. 

    I suggest you look to this great post, http://dev.goshoom.net/en/2011/10/pessimistic-locking/ if you can figure out what is the cause. 

    Otherwise try to share some code.

  • André Arnaud de Calavon Profile Picture
    293,245 Super User 2025 Season 1 on at
    RE: multi threading batch giving error

    Hi Rohit,

    Are you using standard features or a customization to get purchase orders posted in batch? Please provide more details what you have done. Otherwise it would be guessing only.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,245 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,925 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans