Have two process to modify a data at the same time, plus one at a time, there is a problem, but if to get the data at the same time, can cause a process of change is missing, such as data for 5, process of 1, 2 + 1 at the same time, the results should be 7, now the result for the 6.
Framework USES the SSM, the processing of the service layer:
@ Transactional (propagation=propagation. The REQUIRES_NEW) Public String getSerialNumber () { //query data List DocSeqs=docSeqMapper. SelectDocSeq (docSeq); //processing after the update UpdateDocSeq (docSeqs. Get (0), the request). } Mybatis the query in
& lt; Select id="selectDocSeq" & gt; SELECT * FROM the table name The WHERE condition FOR UPDATE & lt;/select> After such treatment does not realize the table lock, two processes will change the same value at the same time, the great god know how to deal with this problem?
CodePudding user response:
- write a statement with lock control
The update tt set nn=nn + 1 where id=1;
CodePudding user response:
reference 1st floor sych888 response: - write a statement with lock control The update tt set nn=nn + 1 where id=1; specific? For update lock on it? Wrote in the XML, and can't lock the data, when you are in PLSQL lock data cannot be updated after, but wrote in the program for update doesn't lock table data?? CodePudding user response:
Do not use for update. It is ok to directly according to the method of 1 #; CodePudding user response:
refer to the second floor u014224177 response: Quote: refer to 1st floor sych888 response: - write a statement with lock control The update tt set nn=nn + 1 where id=1; specific? For update lock on it? Wrote in the XML, and can't lock the data, when you are in PLSQL lock data cannot be updated after, but wrote in the program for update doesn't lock table data?? Statement at the time of execution will lock, Do you use to select for update the truth is the same, execution to selectDocSeq this id will be locked CodePudding user response:
reference 4 floor jdsnhan response: Quote: refer to the second floor u014224177 response: Quote: refer to 1st floor sych888 response: - write a statement with lock control The update tt set nn=nn + 1 where id=1; specific? For update lock on it? Wrote in the XML, and can't lock the data, when you are in PLSQL lock data cannot be updated after, but wrote in the program for update doesn't lock table data?? Statement at the time of execution will lock, You use select for update the truth is the same, to perform selectDocSeq this id will be locked when add breakpoints where processing or sleep, open a web page to another operation data, or would you take to the value, the data is locked in the select is arguably, another web pages should not take to worth? This is the place where I most confused? Is the spring transaction is there a problem? If in PLSQL lock the data, such as when to use the web to operation in a query that is less than the value, CodePudding user response:
reference wmxcn2000 reply: 3/f don't use for update. It is ok to directly according to the method of 1 #; use optimistic locking? A lot of data under concurrent processing will have a problem? CodePudding user response:
reference 5 floor u014224177 reply: Quote: refer to 4th floor jdsnhan response: Quote: refer to the second floor u014224177 response: Quote: refer to 1st floor sych888 response: - write a statement with lock control The update tt set nn=nn + 1 where id=1; specific? For update lock on it? Wrote in the XML, and can't lock the data, when you are in PLSQL lock data cannot be updated after, but wrote in the program for update doesn't lock table data?? Statement at the time of execution will lock, You use select for update the truth is the same, to perform selectDocSeq this id will be locked when add breakpoints where processing or sleep, open a web page to another operation data, or would you take to the value, the data is locked in the select is arguably, another web pages should not take to worth? This is the place where I most confused? Is the spring transaction is there a problem? If in PLSQL lock the data, such as when to use the web to operate in a query that, also less than value, Lock data just don't let the change, does not affect the query, you can take to the data CodePudding user response:
And lock it doesn't matter, the key is on business, when other process whether to allow direct accumulation after the modification of record update and don't need to judge the new data, One, allowing the accumulative Two processes respectively with incremental updates (# 1), rather than using their increased after directly to cover (6) the result of the database field, Second, do not allow the accumulative In condition and update the value of the former, then take the updated record number (SQL % rowcount), 0 indicates other processes have changed data, to the user error, update tt set nn=6 where id=1 and nn=5;