A transaction problem caused by Java Multithreading

Source: Internet
Author: User

A transaction problem caused by Java Multithreading

Business scenarios

We now have a function similar to the file upload function. Each sub-site accepts business and business upload files. Files from each sub-site need to be submitted to the site for storage, files are submitted to the main site in batches. That is to say, there are several hundred files in a batch.

Considering that submitting so many files during the day will affect the bandwidth of other systems on the sub-site, we will submit the files on the sub-site to the station. This operation will be performed independently at night, the specific time is from PM to AM.

This operation process is now called "scheduling ". After the schedule is running, obtain all the batch information that needs to be uploaded to the main site. After obtaining the batch information, set the status of the batch table to synchronizing data. At this time, if another business person uploads files in this batch and finds that the batch is being synchronized, the Operation will fail.

Current problems:

1. The schedule gets the batch. Prepare to set the batch table status to synchronizing. Note that the batch table has not been changed to synchronizing.

2. the business personnel submitted 100 files for this batch. Because the batch table status has not been changed to being synchronized, the verification is passed and the data is inserted to the database, note that the file information has not been inserted into the database at this time, but you are only preparing to insert the file.

3. The schedule sets the batch table information to being synchronized, and obtains all the file information under the batch and saves it To the memory. Prepare to upload files one by one.

4. The File Information uploaded by the business personnel is successfully saved to the database.

In this case, the file information stored in the database in Step 4 is not submitted to the site.

Analysis:

It doesn't matter if you don't understand the above business information. We can describe it in a more popular way:

We went to the cinema to watch 3D movies. If the film was played at and the Broadcasting hall was closed after, then the service staff gave it to allSit in seatThe person who sends a filter lens will have a problem at this time. What should they do? This is our problem.

We have two solutions:

1: We closed the door and waited for a while so that all the people could go to the seat. Then the service staff sent glasses.

2: the service staff checks whether there are people sitting on the seat without glasses and send one without glasses.

Note: In business scenarios, people watching movies cannot take the initiative to ask for glasses.

If the second method is used, dozens of sites frequently access the data query at the terminus. This query is a full table scan, which has a significant impact on the database performance. Considering that this scheduling process is a background process, although the first method is slow, it has less impact on the system and will reduce the CPU pressure on the server to a certain extent, finally, we chose the first solution.

Hope to help you.

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.