Javaweb-how can we prevent multiple users from buying the same product at the same time and place orders for the same product at a high concurrency? Consult

Source: Internet
Author: User
The flash sales system is being launched recently, but the headache is that inventory problems often occur in the case of high concurrency among multiple users. It is found that multiple users place orders at the same time within the same time, causing the query and insertion to be out of sync, there is a time difference between query and insertion, which leads to inventory problems in the case of high concurrency (my project is probably like this, first forupdate finds the commodity information table and puts it into the global table array, after the user successfully deducts the balance, the update item information table minus the number of orders placed by the user. Mysql used in the database is locked when querying the commodity information table, but there is a time difference when querying more and more commodity information table data, in case of high concurrency, when the item information table is queried and put into the variable array... javawebphpupdatejava

The flash sales system is being launched recently, but the headache is that inventory problems often occur in the case of high concurrency among multiple users. It is found that multiple users place orders at the same time within the same time, causing the query and insertion to be out of sync, there is a time difference between query and insertion, which leads to inventory problems in the case of high concurrency (my project is probably like this, first for update to find the commodity information table and put it in the global table array, after the user successfully deducts the balance, the update item information table minus the number of orders placed by the user. Mysql used in the database is locked when querying the commodity information table, but there is a time difference when querying more and more commodity information table data, in case of high concurrency, when the item information table is queried and put into the variable array, other users are placing orders in the time difference following the execution, resulting in inventory problems ). Now, when you ask a question, the same product cannot be snapped up by multiple users within the same period of time. that is to say, in the case of high concurrency within the same second, only one user can place an order. The current idea is to queue and block the queue. But what is the specific implementation idea or whether there are better methods and implementation ideas? if there are cases, it is best. The implementation language is PHP. I would like to ask you about the solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.