网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > Oracle教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.讲解用于描述数据库中需要存储的.
.ORACLE SQL性能优化系列 (二).
.细粒度访问原则.
.终极恢复孰弱孰强-DUL vs AUL.
.oracle中变异表触发器的处理.
.使用过的rman备份集的变化.
.WIN平台下仅开一个端口让Oracle穿.
.逻辑数据模型到物理数据模型的转.
.RedHat AS4 下安装oracle10g.
.探索数据字典,提高自学习Oracle能.
.Jdeveloper3.1.1无法使用OCI8JDBC.
.Oracle中用LogMiner分析重做及归.
.ExactPapers Oracle 1Z0-025 200.
.Oracle数据库回滚段表空间文件丢.
.Oracle Optimizer:迁移到使用基于.
.Oracle中Decode()函数使用技巧.
.实例讲解Oracle的快速删除和快速.
.Oracle数据库.
.通过SELECT语句实现两个记录集的.
.数据库考试简介——Oracle认证.

pessimistic锁定对optimistic锁定(1)

发表日期:2008-2-9


    pessimistic (悲观)locking和optimistic (乐观)locking是Oracle保证数据并行访问和避免lost update的2种策略.     pessimistic (悲观)locking是指用户在读取和更新数据的时候,悲观的认为这期间其他用户可能会更新同一记录;因此在更新数据前读取数据的时候,尝试获得该记录的绝对锁,假如其他用户已经锁住该纪录,则被阻塞用户可以选择等待(select for upodate)还是取消等待(select for update nowait)。从而避免lost update,保证了数据一致性。     optimistic (乐观)locking是指用户在读取和更新数据的时候,乐观的认为这期间其他用户不可能更新同一记录,在更新数据前读取数据的时候,不会获得该记录的绝对锁;因此在更新纪录的时候,其他用户很可能已经修改过了该纪录;因此,在更新的时候需要采取自定义编码策略来避免lost update,保证数据一致性。     演示lost update的例子     At year end, Manager Ian decide to increase engineer SHERSA’s salary by 500$;while HR Officer need to increase each engineer’s salary by 5%.
    Time1: Ian read SHERSA’s salary record:
    SQL> select * from emp where name=' SHERSA ';     ID NAME SALARY     ---------- ------------------------- ----------     8 SHERSA 3000
    Time2: HR read SHERSA’s salary record:
    SQL> select * from emp where name='SHERSA';     ID NAME SALARY     ---------- ------------------------- ----------     8 SHERSA 3000
    Time3: HR update SHERSA’s salary.
    SQL> update emp set salary=salary*1.05 where id=8;     SQL> commit;     SQL> select * from emp where name='SHERSA';     ID NAME SALARY     ---------- ------------------------- ----------     8 SHERSA 3150
    Time4: Ian update SHERSA’s salary by increment 500     SQL> update emp set salary=3500 where id=8;     SQL> commit;     SQL> select * from emp where name='SHERSA';     ID NAME SALARY     ---------- ------------------------- ----------     8 SHERSA 3500     Ian更新的数据覆盖了HR更新的纪录,导致丢失更新(lost update);SHERSA受到了经济损失。     为了避免lost update,需要pessimistic locking 或者optimistic locking。     pessimistic locking 策略     通过在读纪录时,采用select for update锁住该纪录,再进行更新。     Time1: Ian read SHERSA’s salary record:
    SQL> select * from emp where name=' SHERSA ' for update;     ID NAME SALARY     ---------- ------------------------- ----------
    8 SHERSA 3000
    Time2: HR read SHERSA’s salary record:
    SQL> select * from emp where name= ' SHERSA ' for update;     无法获得行上的绝对锁,被另外的session Ian阻塞     Time3: HR has to wait …. Or cancel operation by using “for update nowait”
    SQL> select * from emp where name='SHERSA' for update nowait;     select * from emp where name='SHERSA' for update nowait     *     ERROR at line 1:     ORA-00054: resource busy and acquire with NOWAIT specified
    Get “resource busy”错误
    Time4: Ian update SHERSA’s salary by increment 500     SQL> update emp set salary=3500 where id=8;     SQL> commit;     SQL> select * from emp where name='SHERSA';     ID NAME SALARY     ---------- ------------------------- ----------     8 SHERSA 3500
    Time5: HR update SHERSA’s salary     SQL> update emp set salary=salary*1.05 where id=8;     SQL> commit;     SQL> select * from emp where id=8;     ID NAME SALARY     ---------- ------------------------- ----------     8 SHERSA 3675
上一篇:imp buffer=? & array insert 人气:760
下一篇:pessimistic锁定对optimistic锁定(2) 人气:576
浏览全部Oracle教程的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐