Updating and Fetching using Pessimistic Lock

孤者浪人 提交于 2021-01-29 08:10:49

问题


Need to retrieve latest data whose status is 1 and then setting status 0 for the same using LockMode Pessimistic.

so Db column are => id(autogenerated), count, category_key, status(initially 1 for all).

I have pre-populated data in db where for each category_key combination I have 10000 count....

so lets say for DG_KK I have 1 to 10000 count with status 1 and then for DG_TG I have 1 to 10000 count with status 1. Now

Now I when I pass key DG_KK as category_key then from db using atomic fetch and update using pessimistic mode need to get the count value and then update status 0

so lets say thread1 comes with key DG_KK and get the count 1 and updated status 0 if thread2 comes with key DG_KK at the same time will or should get count 2 and update status 0 for the same and so it follows. But if thread3 comes with DG_TG it will get the count 1 and it follows the same.

来源:https://stackoverflow.com/questions/64712809/updating-and-fetching-using-pessimistic-lock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!