This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1|Reply: 0

[Source] .NET/C# Based on SQL SERVER, uses MERGE + HOLDLOCK for high-concurrency identifiers

[Copy link]
Posted on5 seconds ago | | | |
Requirements: The MERGE + HOLDLOCK used is a one-step atomic operation, which, combined with the locking mechanism, perfectly resolves database-level concurrent conflicts. This article completes the number picker (transmitter) function based on the MSSQL database.

The database creation script is as follows:
The C# code called is as follows:
Execute as shown below:



Testing and sending 10,000 accounts takes about 6 seconds,On average, 1,666 numbers can be taken per second, which can now support most businesses.

Core WITH (HOLDLOCK): This line of code is critical. It represents the use of a Serializable. When multiple threads or multiple services request the same prefix (for example, everyone is competing for the same order number), it can forcibly queue these requests, completely preventing two threads from inserting the same prefix or adding the same number at the same time, ensuring absolute uniqueness and continuity of the numbers.




Previous:The differences between location.assign, location.href, and location.replace
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com