Android role 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, have always felt that the time stamp is to the user to see a data, check the discovery is not, the following is reproduced. We 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 an inference basis for the uniqueness of data. Let me introduce you to how we can use timestamps.

We are bound to encounter this situation: Bank A and Bank B almost at the same time open your account and see your account on the original 1000 Yuan deposit. Then both banks want to add 500 yuan to your account. So. Bank A will change $1000 to $1500 at the same time. Bank B also changed the $1000 to $1500. That's a bad thing!

Finally, your bank account on the last only 1500 yuan instead of the supposedly 2000 yuan, is tantamount to the loss of 500 yuan in vain!

This is the serious problem caused by the change without locking the data.

However, we are able to solve the problem skillfully by time stamping.

Let's look at the idea:

    1. Set the timestamp field timestamp in the Bank Account table. Set to text type varchar.
    2. When bank a reads the deposit field from the Account table, the timestamp field is also read at the same time, for example 123456.

    3. When bank a changes the value of the deposit. When you make a disk operation. A previous read timestamp of 123456 is compared with the time stamp in the current table, assuming the same, then agree to disk. It then generates a new timestamp, such as a 456789 replacement table with time stamp 123456.

What advantages does this bring?

Let's look at the beginning of the situation: Bank A and Bank B almost at the same time open your account and see your account on the original 1000 Yuan deposit, and at the same time two banks at the same time read the timestamp 123456, Then there's a difference. When bank a changes $1000 to $1500, the system will match the timestamp of the previous timestamp 123456 against the time stamp in the table. Obviously. Should now be consistent, then agree to save and generate a new timestamp of 456789 to replace the old timestamp 123456.

Next, bank B also changed 1000 yuan to 1500 yuan, save the system against the previous timestamp 123456 is consistent with the time stamp in the table, found that the previous timestamp 123456 has been different from today's timestamp 456789. The system refused to save, request to refresh the data, then the data refresh after 1000 yuan has been due to a bank deposited 500 yuan and became 1500 yuan. Then Bank B will be 1500 yuan on the basis of the change to 2000 yuan, save again, the system agreed. In this way, we avoid the errors caused by repeated changes to the data.

Some like tongue twisters, I hope we all know what I mean ~

Android role 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.