The role of the Android timestamp

Source: Internet
Author: User

I was in the video with the mediarecorder of the problem of the synchronization of videos and audio, asked some people after the feeling should be no time stamp, before always think time stamp is to show users a data, check the discovery is not, the following is reproduced, I hope to be useful to you:

Let's first introduce you to what a timestamp is.

in layman's terms, a timestamp is a set of random numbers generated from the current system time. Timestamps are generally used as a basis for judging the uniqueness of data. Let me tell you about how we can use timestamps.

We are bound to encounter this situation: Bank A and Bank B almost simultaneously open your account and see your account on the original 1000 yuan deposit, and then both banks want to add 500 yuan deposit to your account. Then, bank A will change $1000 to $1500 and Bank B will change $1000 to $1500. That's a bad thing! Finally, your bank account last only 1500 yuan instead of the supposedly 2000 yuan, equals the loss of 500 yuan in vain! This is the serious problem caused by the modification without locking the data. However, we can solve this problem skillfully by time stamping.

Let's look at the idea:

    1. In the Bank Account table, set the timestamp field timestamp to the text type varchar.
    2. When bank a reads the deposit field in the Account table, it also reads the timestamp field, such as 123456.
    3. When bank a modifies the value of the deposit, the previous read timestamp of 123456 is compared with the timestamp in the current table, and if it is consistent, it is allowed to save and then generate a new timestamp such as 456789 of the time stamp in the replacement table 123456.

what is the benefit of doing so?

Let's look at the beginning of the situation: Bank A and Bank B almost simultaneously open your account and see your account on the original 1000 yuan deposit, while two banks simultaneously read the timestamp 123456, then there is a difference, When bank a changes 1000 yuan to 1500 yuan, the system will compare the previous timestamp 123456 with the time stamp in the table, obviously, now should be consistent, then allow to save, and generate a new timestamp 456789 replaced the old timestamp 123456. Next, bank B also changed 1000 yuan to 1500 yuan, save, the system compared to the previous timestamp 123456 is the same as the time stamp in the table, found that the previous timestamp 123456 has been different from the current time stamp 456789, the system refused to disk, the request to refresh the data, After the data refresh 1000 yuan already because before a bank deposited 500 yuan and became 1500 yuan, then Bank B will be on the basis of 1500 yuan to 2000 yuan, save again, the system allows. In this way, we avoid the error of repeating data changes!

Some like tongue twisters, hope everybody already understood my meaning ~

The role of the Android timestamp

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.