在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.pswp.cn/news/271099.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/271099.shtml
英文地址,請注明出處:http://en.pswp.cn/news/271099.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

條件隨機場 python_用條件隨機場做網絡小說命名實體識別

一直想用統計學習方法來改善撥云搜索&#xff0c;這次先在命名實體上小小嘗試一下。線性鏈條件隨機場對于無向圖中的節點&#xff0c;定義一組特征函數&#xff0c;使其狀態僅受鄰近節點和觀測序列的影響。在標注任務中&#xff0c;節點只有前后兩個鄰近節點&#xff0c;即線性…

項目開發基礎:常用測試方法介紹

1、集成測試集成測試就是把模塊按照設計說明書的要求組合起來進行測試。1.1、集成測試方法&#xff1a;a、分別測試各個模塊&#xff0c;再把這些模塊組合起來進行整體測試&#xff0c;也就是非增量式集成。特點&#xff1a;可以對模塊進行并行測試&#xff0c;能充分利用人力&…

java 多數據源處理_java – 用于處理多個數據源的Spring事務管理

這可能是一個重復的問題,但我找不到(至少我無法理解)一個滿意的答案,因此再次提問.我正在使用兩個數據源(MySQL和Oracle).以下是執行流程&#xff1a;主方法-A調用方法-B(寫入Oracle DB)然后它(方法-A)調用方法-C(寫入mySQL DB)然后它(方法-A)調用方法-D(寫入Oracle DB) ).如果…

MyBatis Generator

1 <?xml version"1.0" encoding"UTF-8"?>2 <!DOCTYPE generatorConfiguration3 PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"&g…

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…

實時數據處理插件開發flume+kafka+storm:flume

有時間了再寫。。。。轉載于:https://www.cnblogs.com/wchb/p/5786582.html

項目管理基礎:系統維護相關知識筆記

1、系統的可維護性系統的可維護性就是項目維護人員理解、改正、改動和改進該軟件的難易程度。提高系統的可維護性是開發軟件吸引所有步驟的關鍵目的&#xff0c;系統能否被很好地維護&#xff0c;可用系統的可維護性這一指標來衡量。1.1 系統可維護性的評價指標可理解性&#x…

java ibm 2035,C# java 連接 IBM MQ時出現 2035 或 2013認證錯誤的解決方法

當C# 或 java 連接 IBM MQ 是出現 2035 或 2013的錯誤時java的錯誤提示&#xff1a;com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: 為隊列管理器“QM1”提供的安全性認證無效&#xff0c;連接方式為“Client”&#xff0c;主機名為“9.186.105.212(1414)”…

python給兩個列表排序方法_Python連接兩個字符串列表并對其元素排序的最佳方法...

假設我有兩個字符串列表&#xff1a;x[a,b] and b[c,d]我需要的最終結果是&#xff1a;^{pr2}$重要的一點是&#xff0c;我希望對列表元素的字母進行排序。在這里&#xff0c;他們是建設&#xff0c;但在我的實際問題&#xff0c;這不是這樣。所以如果我有“ba”&#xff0c;在…