Consistency of the database read, stolen, multi-threaded and stolen read, Acid,undo

Source: Internet
Author: User
Tags rollback

Stolen Dirty Read

For the object of the synchronous asynchronous method, we design our own program, we must consider the overall problem, otherwise there will be inconsistent data errors, very classic is stolen (Dityread)

Example:

?

Package Com.nbkj.thread;public class Dityread {private String username = "hsj179540";    Private String Password = "123";        Public synchronized void SetValue (string username, string password) {this.username = username;        try {thread.sleep (2000);        } catch (Interruptedexception e) {e.printstacktrace ();        } this.password = password;    System.out.println ("SetValue The end result is: Username:" + this.username + ", Password:" + This.password);  }/*synchronized */public synchronized void Getvlaue () {System.out.println ("The end result of GetValue is: Username:" +    This.username + ", Password:" + This.password);        public static void Main (string[] args) throws Exception {final Dityread dityread = new Dityread (); Thread t1 = new Thread (new Runnable () {@Override public void run () {Dityread.setval            UE ("Zs", "ZSP");        }}, "T1"); /* Thread t2 = new Thread(New Runnable () {* * @Override public void Run () {* *}}, "T2");        */T1.start ();        Thread.Sleep (1000);    Dityread.getvlaue (); }}
Summarize:

? Consider the problem when you must consider the integrity of the problem, when the SetValue execution, do not want to getvalue execution, so GetValue also to lock, so as to ensure synchronization, otherwise may cause stolen.

Four characteristics of a relational database: ACID

Atomicity (atomicity), consistency (consistency), isolation (isolation), persistence (durability)

1.oracle Undo Concept:

When you perform DML operations, the old values that you perform are logged for easy rollback. Equivalent to Ctrl +z

2. Classic error: Snapshot too old

When the rollback is not found value, will error snapshot too old

Reflects the consistency of the database read pictures do not display can be copied image address to the browser view

If you have any questions, you can contact me wx:hsj179540

Consistency of the database read, stolen, multi-threaded and stolen read, Acid,undo

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.