web
You’re offline. This is a read only version of the page.
close
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 439

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

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    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.

  • enricoariel Profile Picture
    60 on at

    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.

  • rohit1900 Profile Picture
    439 on at

    /// /// 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; } } }

  • rohit1900 Profile Picture
    439 on at

    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
    439 on at

    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
    439 on at

    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.

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at

    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)

  • enricoariel Profile Picture
    60 on at

    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

  • enricoariel Profile Picture
    60 on at

    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);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans