資料庫的一致性讀,贓讀,多線程與贓讀,ACID,UNDO

來源:互聯網
上載者:User

標籤:分享圖片   ted   sleep   記錄   自己   print   操作   rup   throws   

贓讀

對於對象額同步非同步方法呼叫,我們在設計自己的程式的時候,一定要考慮的問題整體,不然會出現資料不一致的錯誤,很經典的就是贓讀(dityread)

樣本:

?

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的最終結果是:username:" + this.username + ",password:" + this.password);    }        /*synchronized */    public synchronized void getVlaue() {        System.out.println("getValue的最終結果是: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.setValue("zs", "zsp");            }        }, "t1");        /*         * Thread t2 = new Thread(new Runnable() {         *          * @Override public void run() {         *          * } }, "t2");         */        t1.start();        Thread.sleep(1000);        dityRead.getVlaue();    }}
總結:

? 考慮問題的時候一定要考慮問題的整體性,當setValue執行的時候,不想getValue執行,所以getValue也要加鎖,這樣才能保證同步,不然可能引起贓讀。

關係型資料庫的四個特性:ACID

原子性(Atomicity)、一致性(Consistency)、隔離性(Isolation)、持久性(Durability)

1.oracle undo概念:

當執行DML操作的時候,會記錄你執行的舊值方便復原。相當於Ctrl +Z

2.經典錯誤:snapshot too old

當復原的時候找不到值,會報錯snapshot too old

體現了資料庫的一致性讀 圖片不顯示的可以複製圖片地址到瀏覽器查看

有問題可以聯絡我 WX:hsj179540

資料庫的一致性讀,贓讀,多線程與贓讀,ACID,UNDO

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.