Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

What happens when a SysOperation job that updates a table fields is been run simultaneously by two users

(0) ShareShare
ReportReport
Posted on by 109

Currently we have a sysOperation job in which we are deleting the records in a table and inserting new calculated fields in a service class. We are not using any ttsbegin ttscommit or putting it inside a try catch. I am just trying to understand how will the system work if two or more users run the service class simultaneously at the same time. Are there any preventive measures that we could take to avoid such situation? 

  • JohnBright Profile Picture
    JohnBright 109 on at
    RE: What happens when a SysOperation job that updates a table fields is been run simultaneously by two users

    Thank you Martin for your time, will do the same.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,868 Most Valuable Professional on at
    RE: What happens when a SysOperation job that updates a table fields is been run simultaneously by two users

    If you always want to use the table(s) in this way, disabling OCC directly on the table is the easiest way.

  • JohnBright Profile Picture
    JohnBright 109 on at
    RE: What happens when a SysOperation job that updates a table fields is been run simultaneously by two users

    Hi Martin, Sorry that I didn't mentioned in my previous comment. In our service class we are performing multiple insert_Recordset operation and update_recordset operation on different groupings of records. I have seen code to set pessimistic locking in select statements but not sure how to activate the pessimistic locking for inser_recordset or Update_recordset. Please can you advice on that?

    Also, will changing the table property OCC enabled to no will do the trick on pessimistic locking?

  • Martin Dráb Profile Picture
    Martin Dráb 230,868 Most Valuable Professional on at
    RE: What happens when a SysOperation job that updates a table fields is been run simultaneously by two users

    That's a simple scenario. Do the work in a transaction and use pessimistic locking.

    When the second session tries to delete data from the table, it'll be blocked until the exclusive lock is released. When the original transaction completes, the second sessions continues - it deletes all the records created a moment ago and runs the same logic to generates them once more.

  • JohnBright Profile Picture
    JohnBright 109 on at
    RE: What happens when a SysOperation job that updates a table fields is been run simultaneously by two users

    Hi Martin, thanks for your response. 

    For the first question, we are not generating any user specific data. All users have the same set of data. 

    For second question, Yes when two users launches the batch job I want the second user's batch to wait and then run once the first user's job get's over. Can you please advice on how can we achieve this? 

  • Martin Dráb Profile Picture
    Martin Dráb 230,868 Most Valuable Professional on at
    RE: What happens when a SysOperation job that updates a table fields is been run simultaneously by two users

    It depends on what you want to achieve. If you want each users to have a separate set of data, then your design is wrong and you'll need to come with a different one. For example, you may want to use a temporary table, partition data by user ID or a session ID or so.

    If all users should use the same same set of data and you just want to prevent multiple refreshes at the same time, decide that should happen. For example, if you run the job and another is already running, does it make sense to wait for completion and immediatelly running the same thing again? Or what should happen?

    I suspect that you really need to redesign the thing. It doesn't sound like something designed for a multi-user system.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans