A problem of things caused by Java multithreading

Source: Internet
Author: User

Business Scenarios

We now have a function similar to file upload, each sub-site accept business, business upload files, the files of each sub-site need to be submitted to the total site to save, file is submitted to the total site by batches, that is, a batch under about hundreds of files.

Considering that filing so many files during the day will affect the other system bandwidth of the sub-site, we will submit the sub-site files to the total site this operation process Independent, put in the evening to do, the specific time is 7:00 to 7:00 in the morning.

This procedure is called "scheduling" for the time being. After the schedule is run, get all the batch information that needs to be uploaded to the total site, after getting the batch information, set the status of the batch table to synchronizing data, this time, if the batch has another business person to upload the file, found that the batch is synchronizing, will return the operation failed.

The problem now arises:

1, scheduled to get to the batch, ready to set the Batch table status is synchronizing, note that this time the batch table has not changed to synchronizing.

2, the business staff to submit 100 files for this batch, because the Batch table status has not changed to synchronizing, so the verification through, ready to insert data into the database, note that this time the file information is not inserted into the database, just ready to insert.

3, Schedule the batch table information to be synchronized, and get to the batch below all the file information to save to memory, prepare an upload file.

4. The file information uploaded by the business personnel is successfully saved to the database.

In this case, the file information saved to the database in the fourth step is not submitted to the total site.

Analysis:

People don't understand the business information above, it's okay, we can describe it in a more popular way:

We go to the cinema to see the 3D movie, if the movie is broadcast at 9:00, after 9:00, the studio Hall closes, and then the service staff to all the seats in the person to send a filter glasses, this time there will be a problem, those who are heading to the table what to do? This is the problem we have now.

We think of 2 solutions:

1: We wait for some time after closing the door, let all the people go to the seat, then the service staff again hair glasses.

2: The service personnel at intervals at a time to detect, there is no seat on the person without glasses, no glasses on the hair.

Note: The people who see movies in business scenarios are not able to take the initiative to get glasses J

If you use the second method, our dozens of sub-sites will frequently access the total site query data, this query is a full table scan, which has too much impact on database performance. Considering that this scheduling process is a background process, the first approach, though slow, has less impact on the system and, to some extent, slows down the CPU pressure on the server, and finally we choose the first scenario.

Hope to be of help to 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.