在db2数据库上模拟死锁场景 还是z上的

如果条件允许,起两个线程互相抢资源就行了,但问题是,时间上还需要同步,要做到完美控制,还得加其他逻辑,忒费事,所以可以用下面的办法:

在目标表上直接加个锁……简单,粗暴,直接……很好……

LOCK TABLE

The LOCK TABLE statement requests a lock on a table or table space at the current server. The lock is not acquired if the process already holds an appropriate lock.

Invocation

This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared.

Authorization

The privilege set that is defined below must include at least one of the following:

  • The SELECT privilege on the identified table (the SELECT privilege does not apply to the auxiliary table)
  • Ownership of the table
  • DBADM authority for the database
  • SYSADM or SYSCTRL authority
  • Start of changeDATAACCESS authorityEnd of change

If the database is implicitly created, the database privileges must be on the implicit database or on DSNDB04.

Privilege set: If the statement is embedded in an application program, the privilege set is the privileges that are held by the owner of the plan or package. If the statement is dynamically prepared, the privilege set is determined by the DYNAMICRULES behavior in effect (run, bind, define, or invoke) and is summarized in Table 1. (For more details on these behaviors, including a list of the DYNAMICRULES bind option values that determine them, see Authorization IDs and dynamic SQL.)

Syntax

Read syntax diagram

>>-LOCK TABLE--table-name--+--------------------+--------------->'-PARTITION--integer-'   >--IN--+-SHARE-----+--MODE-------------------------------------><'-EXCLUSIVE-'         

Description

table-name
Start of changeIdentifies the table to be locked. The name must identify a table that exists at the current server. It must not identify a view, a temporary table (created or declared), an accelerator-only table, or a catalog table. The lock might or might not apply exclusively to the table. The effect of locking an auxiliary table is to lock the LOB table space that contains the auxiliary table.End of change
PARTITION integer
Identifies the partition of a partitioned table space to lock. The table identified by table-name must belong to a partitioned table space. The value specified for integer must be an integer that is no greater than the number of partitions in the table space.
IN SHARE MODE
For a lock on a table that is not an auxiliary table, requests the acquisition of a lock that prevents other processes from executing anything but read-only operations on the table. For a lock on a LOB table space, IN SHARE mode requests a lock that prevents storage from being reallocated. When a LOB table space is locked, other processes can delete LOBs or update them to a null value, but they cannot insert LOBs with a nonnull value. The type of lock that the process holds after execution of the statement depends on what lock, if any, the process already holds.
IN EXCLUSIVE MODE
Requests the acquisition of an exclusive lock for the application process. Until the lock is released, it prevents concurrent processes from executing any operations on the table.
Exception: Unless the lock is on a LOB table space, concurrent processes that are running at an isolation level of uncommitted read (UR) can execute read-only operations on the table.

Start of changeBe aware that an exclusive lock on a table space, table, or partition does not prevent other transactions from holding claims on the locked object.End of change

Notes

Releasing locks:
If LOCK TABLE is a static SQL statement, the RELEASE option of bind determines when DB2® releases a lock. For RELEASE(COMMIT), DB2 releases the lock at the next commit point. For RELEASE(DEALLOCATE), DB2 releases the lock when the plan is deallocated (the application ends).

If LOCK TABLE is a dynamic SQL statement, DB2 uses RELEASE(COMMIT) and releases the lock at the next commit point, unless the table or table space is referenced by cached dynamic statements. Caching allows DB2 to keep prepared statements in memory past commit points. In this case, DB2 holds the lock until deallocation or until the commit after the prepared statements are freed from memory. Under some conditions, if a lock is held past a commit point, DB2 demotes the lock state of a segmented table or a nonsegmented table space to an intent lock at the commit point.

Start of changeWhen you issue the MODIFY DDF PKGREL(BNDOPT) or MODIFY DDF PKGREL command, the use of processor resources for package allocation and deallocation are minimized for packages that use database access threads and are bound with RELEASE(DEALLOCATE). When the MODIFY DDF PKGREL(BNDOPT) command has been issued, DB2 honors the RELEASE bind option even for dynamic SQL statements.End of change

Syntax alternatives and synonyms:
For compatibility with previous releases of DB2, PART can be specified as a synonym for PARTITION.

Example

Obtain a lock on the sample table named DSN8A10.EMP, which resides in a partitioned table space. The lock obtained applies to every partition and prevents other application programs from either reading or updating the table.
   LOCK TABLE DSN8A10.EMP IN EXCLUSIVE MODE;

 

转载于:https://www.cnblogs.com/sthv/p/5780376.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/271099.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

项目开发基础:常用测试方法介绍

1、集成测试集成测试就是把模块按照设计说明书的要求组合起来进行测试。1.1、集成测试方法&#xff1a;a、分别测试各个模块&#xff0c;再把这些模块组合起来进行整体测试&#xff0c;也就是非增量式集成。特点&#xff1a;可以对模块进行并行测试&#xff0c;能充分利用人力&…

svd奇异值分解_NCL专辑 | 奇异值分解(SVD)

奇异值分解SVD(Singular Value Decomposition)是一种矩阵分解方法&#xff0c;在气象领域中常用来分析两个气象场场之间的关系。NCL的函数库中与SVD相关的函数包括svd_lapack&#xff0c;svdcov&#xff0c;svdcov_sv&#xff0c;svdstd&#xff0c;svdstd_sv。svd_lapack&…

项目测试基础:白盒测试相关知识笔记

1、白盒测试概念白盒测试又称为结构测试&#xff0c;主要是根据程序的内部结构和逻辑来设计测试用例&#xff0c;然后对程序的路径和过程进行测试&#xff0c;检查是否满足设计的需要。2、白盒测试常用的技术介绍白盒测试常用的技术有逻辑覆盖、循环覆盖、基本路径测试。2.1 逻…

java全局变量和局部变量

分类&#xff1a; 变量按作用范围划分分为全局变量&#xff08;成员变量&#xff09;和局部变量 成员变量按调用方式划分分为实例属性与类属性 局部变量按定义位置划分分为形参&#xff0c;方法局部变量&#xff0c;代码块局部变量 成员变量&#xff1a; 直接在类中声明的…

电脑系统知识:Windows原版系统与Ghost系统的区别,你知道吗?

经常看到有电脑小白的朋友问原版操作系统跟Ghost的区别是什么&#xff0c;该怎么选择安装哪种系统&#xff1f;今天在这里就说说它们之间的联系与区别。Windows原版系统&#xff1a;原版系统就是微软推送给用户的原始“干净”的系统。系统不含第三方的软件&#xff0c;软件补丁…

sql server update触发器_SQL Server 触发器

T-SQL 触发器触发器分为BEFORE触发器*(SQL Server不支持&#xff0c;Oracle支持)在事件发生时触发。AFTER触发器是 SQLServer生成的最初用于自动相应数据修改的机制。在 SQLServer200以前的版本中 AFTER触发器是唯一的触发器&#xff0c;因此不用指明 AFTER&#xff0c;也可以用…

iOS 公司开发者账号申请

对于独立开发者很有用,收藏起来,以备不时之需! 苹果开发者账号分三种。 个人账号&#xff1a;个人申请用于开发苹果app所使用的账号&#xff0c;仅限于个人使用&#xff0c;申请比较容易&#xff0c;$99。 公司账号&#xff1a;以公司的名义申请的开发者账号&#xff0c;用于公…

php渲染视图,Laravel 视图渲染:Blade 模板引擎

Laravel 视图渲染&#xff1a;Blade 模板引擎由 学院君 创建于3年前, 最后更新于 2年前版本号 #153378 views27 likes0 collectsBlade 简介Blade 是由 Laravel 提供的非常简单但功能强大的模板引擎&#xff0c;不同于其他流行的 PHP 模板引擎&#xff0c;Blade 在视图中并不约束…

项目管理基础:系统切换相关知识笔记

1、系统试运行主要任务对新系统进行初始化、补录各种原始数据记录记录系统运行过程中的数据和状况核对新旧系统输出结果是否正确对实际系统的输入方式进行考察主要包括是否方便、效率、可靠性、误操作保护等方面。对系统实际运行、响应速度进行实际测试&#xff0c;确定是否满足…

sql 分组统计_leetcode-sql面试题十七篇精讲合集

这可能是全网最干货的sql讲解系列文章。全系列共十七讲。做了大量的知识点的拓展&#xff0c;涵盖了sql的方方面面。欢迎关注点赞收藏&#xff0c;正在整理三年数据分析的点点滴滴。包括Excel、python、sql、power BI、各种分析模型框架。保证输出最干的干货。涉及知识点包括&a…

项目管理基础:系统维护相关知识笔记

1、系统的可维护性系统的可维护性就是项目维护人员理解、改正、改动和改进该软件的难易程度。提高系统的可维护性是开发软件吸引所有步骤的关键目的&#xff0c;系统能否被很好地维护&#xff0c;可用系统的可维护性这一指标来衡量。1.1 系统可维护性的评价指标可理解性&#x…

一个栈桢对应着一个方法

一个栈桢对应着一个方法

程序员幽默:39个奇葩代码注释,每一个都能笑抽

1. 只有上帝知道//我写这一行的时候&#xff0c;只有上帝和我知道我在写什么//现在&#xff0c;只有上帝知道了2. 相隔时空的diss//somedev1 - 6/7/02 添加对登录屏幕的暂时追踪功能//somedev2 - 5/22/07 暂时个屁&#xff08;仿佛看到两个程序员相隔时空的diss&#xff09;3…

栈出现的异常和设置栈的大小-Xss

异常 java.lang.StackOverflowError 看下面的例子&#xff0c;默认的栈内存 设置栈内存 使用参数-Xss大小来设置栈的大小

项目管理基础:系统评价相关知识

1、概念软件系统的评价分为广义评价和狭义评价。广义评价&#xff1a;主要是指系统从开发开始到结束的过程中&#xff0c;每个阶段都要进行系统评价。狭义评价&#xff1a;主要是指在系统建成后并投入运行之后进行全面、综合的评价。2、广义评价分类根据时间与软件系统所处的阶…

AutoHotKey程序防止反编译的简单手段

可以使用AutoHotKey自带的工具。 AutoHotKey安装完成后&#xff08;我使用的是1.1.0.0&#xff09;&#xff0c;找到安装所在目录下的文件&#xff1a;\Compiler\Ahk2Exe.exe。 程序界面如下&#xff1a; 简单使用&#xff1a; 1、选择源文件&#xff08;script file) 2、选择目…

table合并单元格_制作课程表3——合并单元格

由于浏览器兼容问题&#xff0c;、 以及 很少被使用&#xff0c;所以我们将课程表依然使用tr、td元素&#xff0c;结合样式实现出前面案例中效果原来代码&#xff1a;课程1 课程2 课程3 课程4 课程5 课程1 课程2 课程3 课程4 课程5 课程1 课程2 课程3 课程4 课程5 课程1 …