在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
- DATAACCESS authority
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
>>-LOCK TABLE--table-name--+--------------------+--------------->'-PARTITION--integer-'???>--IN--+-SHARE-----+--MODE-------------------------------------><'-EXCLUSIVE-' ???Description
table-nameBe aware that an exclusive lock on a table space, table, or partition does not prevent other transactions from holding claims on the locked object.
Notes
Releasing locks: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.
When 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.
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
總結
以上是生活随笔為你收集整理的在db2数据库上模拟死锁场景 还是z上的的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Gateway Sentinel 做网关
- 下一篇: java 二进制文件修改_Java读写二