首页 | 互联网 | IT动态 | Cisco | Windows | Linux | Java | .Net | Oracle | 华为 | 存储世界 | 服务器 | 网络设备 | IDC | 安全 | 求职招聘
IT培训 | 数字网校 | 技术专题 | 电子书下载 | 教学视频 | 网页设计 | 平面设计 | 解决方案 | 直播室 | 虚拟考场 | 搜索 | 博客 | 沙龙 | 论坛
中国IT实验室Linux频道
中国IT教育
 
首页 资讯动态 认证考试 新手入门 核心技术 高级技术 J2EE J2ME Java&XML 开源技术 其他技术 RSS订阅 论坛 专题
您现在的位置: 中国IT实验室 >> Java >> J2EE >> JDBC/JDO >> 文章正文

oracle 事务隔离级别,用jdbc体验

文章来源中国IT实验室收集整理 作者佚名 更新时间2007-5-17 保存本文保存本文 推荐给好友推荐给好友 收藏本页收藏本页

    做技术支持 2 个月了,也就是说有 2 个月没有碰代码了,手都很生了,最近遇到项目大的并发问题,数据也有些不太正确,就想到了项目中,由于模块过多,异步的情况也有发生,所以想到事务与锁的相关知识,先写一点事务相关的理解,然后写一点锁相关的东西,以便加深自己的理解。

 

    Oracle 支持的 2 种事务隔离级别 Read committed Serializable

JDBC 进行了测试和学习,根据自己的理解写点心得,这里全部是我个人的看法和理解,如果错误之处请大家告诉我,以便误导他人同时也会使我学习到更多的东西。

 

 

所需数据准备如下:

item

item_value

action_time

id

aaa

LOOCKY

06-12-2006 15:23:54

1

tsindex

users

06-12-2006 15:23:54

2

tstemp

temp

06-12-2006 15:23:54

3

 

来自 oracle 官方网站的 Read committed Serializable 的解释

 

Isolation Level

Description

Read committed

This is the default transaction isolation level. Each query executed by a transaction sees only data that was committed before the query (not the transaction) began. An Oracle query never reads dirty (uncommitted) data.

Because Oracle does not prevent other transactions from modifying the data read by a query, that data can be changed by other transactions between two executions of the query. Thus, a transaction that runs a given query twice can experience both nonrepeatable read and phantoms.

Serializable

Serializable transactions see only those changes that were committed at the time the transaction began, plus those changes made by the transaction itself through INSERT , UPDATE , and DELETE statements. Serializable transactions do not experience nonrepeatable reads or phantoms.

 

2 者的区别也是来自官方网站

summarizes key differences between read committed and serializable transactions in Oracle.

Table 13-2 Read Committed and Serializable Transactions

 

Read Committed

Serializable

Dirty write

Not possible

Not possible

Dirty read

Not possible

Not possible

Nonrepeatable read

Possible

Not possible

Phantoms

Possible

Not possible

 

 

上面的 2 个表来自 http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14220/consist.htm

都可以随时查询

 

 

Isolation Level

Description

Read committed

This is the default transaction isolation level. Each query executed by a transaction sees only data that was committed before the query (not the transaction) began. An Oracle query never reads dirty (uncommitted) data.

Because Oracle does not prevent other transactions from modifying the data read by a query, that data can be changed by other transactions between two executions of the query. Thus, a transaction that runs a given query twice can experience both nonrepeatable read and phantoms.

默认的隔离级别设置。事务中的查询只能看到在此查询之前( 而非事务开始之前 )提交的数据。

由于 oracle 不会因为查询数据而阻止另外一个事务修改数据,因此数据可以在一个事务中的 2 次查询中,查到不同的结果。因此

可能出现 nonrepeatable read and phantoms 的情况

 

 

 

 

 

Serializable

Serializable transactions see only those changes that were committed at the time the transaction began, plus those changes made by the transaction itself through INSERT , UPDATE , and DELETE statements. Serializable transactions do not experience nonrepeatable reads or phantoms.

 

根绝我的理解解释一下:

serializable transactions 在事务执行: 2 次同一条数据查询的时候(就是两次执行查询,就是说执行完第一个 .executeQuery ,然后执行第二个 .executeQuery ),如果在第一个 .executeQuery 开始执行而另外一个事务已经开始修改数据,并且已经提交,那么两次读取的数据是另外一个事务修改前的数据。

如果在第一个 .executeQuery 之前,另外一个事务修改了数据,那么两次读取的数据是另外一个事务修改后的数据。

这恰恰反映了, repeatable read ,两次结果一致

这与 Read committed 完全不同,

要是 Read committed ,第一个 .executeQuery 未执行完第二事务,而在第二个 .executeQuery 前第二个事务执行完毕,那么第一个 .executeQuery 得到的是初始数据,而第二个 .executeQuery 得到的是修改后的数据

恰恰说明了 nonrepeatable read ,两次结果不一致的情况

 

 

 

[1] [2] [3] 下一页  

【责编:Youping】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·超前体验 Oracle 11g的5个新特性
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题
 ·展现C#世界 C#程序设计专题
 ·Java入门 Tomcat的配置技巧精华专题
 ·Oracle RMAN物理备份技术详解
 ·JAVA开发利器——JBuilder知多少
 ·Hello,web2.0技术进阶专题
 ·从入门到精通 java初学者实践系列教程
 ·JAVA 与 .NET两强对垒 到底该选什么?
 今日更新
 社区讨论
 博客论点
 频道精选
 Java 频道导航