標籤:分享圖片 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