• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Database » Rdbms » What is Starvation During Granting of Locks
Next →
← Prev

What is Starvation During Granting of Locks

By Dinesh Thakur

When a transaction requests a lock on a data item in a particular mode, and no other transaction has a lock on the same data item in a conflicting mode, the lock can be granted. However care must be taken to avoid the following scenario.

Suppose a transaction T2 has a shared-mode lock on a data item, and another transaction T1 requests an exclusive mode lock on the data item. Clearly, T1 has to wait for T2 to release the share mode lock. Meanwhile a transaction T3 may request a shared mode lock on the same data item. The lock request is compatible with the lock granted to T2 so T3 may be granted the shared mode lock. At this point T2 may release the lock, but still T1 has to wait for T3 to finish. But again there may be a new transaction T4 that request a shared mode lock on the same data item and is granted the lock before T3 releases it. In fact, it is possible that there is a sequence of transactions that each request a shared mode lock on the data item and each transaction release the lock a short while after it is granted, but T1 never gets the exclusive mode lock on the data item. The transaction T1 may never make progress and is said to be starved.

We’ll be covering the following topics in this tutorial:

  • Solution of Starvation Problem
  • Objective: To visualize the locking procedure in Oracle.

Solution of Starvation Problem

We can avoid starvation problem of transactions by granting locks as follows:

1.   If a shared lock is requested, the queue of requests is empty, and the object is not currently locked in exclusive mode, the lock manager grants the lock and updates the lock table entry for the object (indicating that the object is locked in shared mode and incrementing the number of transactions holding a lock by one).

2.   If an exclusive lock is requested, and no transaction currently holds a lock on the object (which also implies the queue of requests is empty) the lock manager grants. the lock and updates the lock table entry.

Objective: To visualize the locking procedure in Oracle.

Locking in Oracle: In Oracle default locking is row exclusive lock for Update/ Delete/ Insert.

Step 1: Open two instances of SQL PLUS on your machine and login with user name ‘scott’ and password ‘tiger’ or your own Oracle ID in both.

Step 2: Go to first instance.

Write the following query:

SQL>update EMP set sal=7000 where empno=7369;

Step 3: Go to second instance.

Write the following query:

SQL>update EMP set sal=5000 where empno=7369;

Step 4: Go to first instance and issue COMMIT/ ROLLBACK.

Step 5: Go to second instance. You get the SQL prompt.

Step 6: Issue COMMIT/ ROLLBACK in the second instance as well.

Summary of this exercise:

You have just learnt

• Update/ Delete/ Insert DML statement in Oracle acquire a row exclusive lock.

• The exclusive lock is released only at the end of transaction which is marked by commit/ Rollback.

Objective: To visualize how deadlock occurs in Oracle.

Step 1: Open two instances of SQLPLUS on your machine and login with user name ‘scott’ and password ‘tiger’ or your own Oracle ID in both.

Step 2: Go to first instance.

Write the following query:

SQL>update EMP set sal=7000 where empno=7900;

Step 3: Go to second instance.

Write the following query:

SQL>update EMP set sal=5000 where empno=7902;

Step 4: Go to first instance.

Write the following query:

SQL>update EMP set sal=7000 where empno=7902;

Step 5: Go to second instance

Write the following query:

SQL>update EMP set sal=6000 where empno=7900;

Step 6: Issue COMMIT/ ROLLBACK III both the instances

Summary of this exercise:

You have just learnt

• How to visualize the deadlock.

• Oracle intelligently determines the deadlock situation

3.   Otherwise, the requested lock cannot be immediately granted and the lock request is added to the queue of lock requests for this object. The transaction requesting the lock is suspended.

Note that if T1 has a shared lock on A and T2 requests an exclusive lock, T2 request is queued. Now if T3 requests a shared lock, its request enters the queue behind that of T2, even though the requested lock is compatible with the lock held by T1. This rule ensures that T2 does not starve, that is, wait indefinitely while a stream of other transactions; acquire shared locks and thereby prevent T2 from getting the exclusive lock that is waiting for.

You’ll also like:

  1. Explicit Locks in Java Example
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

DBMS

Database Management System

    • DBMS - Home
    • DBMS - Definition
    • DBMS - What is
    • DBMS - Entity Sets
    • DBMS - Components
    • DBMS - Languages
    • DBMS - Normalization
    • DBMS - Data Models
    • DBMS - Processing System
    • DBMS - Advantages
    • DBMS - ER-Model
    • DBMS - Functional Dependence
    • DBMS - Relational Model
    • DBMS - Architecture
    • DBMS - Network Model
    • DBMS - Approach
    • DBMS - Data Independence
    • DBMS - Relational Schema
    • DBMS - Instance
    • DBMS - Functions and Service
    • DBMS - Server
    • DBMS - DBA
    • DBMS - Instance & Schemas
    • DBMS - System Type
    • DBMS - DDL, DML and DCL
    • DBMS - Users
    • DBMS - Model
    • DBMS - System Structure
    • DBMS - Role of DBA
    • DBMS - Metadata
    • DBMS - ER-Diagram
    • DBMS - E-R Model Problems
    • DBMS - DBMS Vs.RDBMS
    • DBMS - Basic Construction of E-R
    • DBMS - E-R Notation
    • DBMS - Database View
    • DBMS - Concurrency Control
    • DBMS - Schema
    • DBMS - Procedure for Access
    • DBMS - Object
    • DBMS - dBase
    • DBMS - Relational Algebra
    • DBMS - Deadlock
    • DBMS - Relational Database
    • DBMS - Query
    • DBMS - Schema

DBMS Normal Forms

    • Database - CODD’S Rules
    • Database - 1NF
    • Database - 2NF
    • Database - 3NF
    • Database - 4NF
    • Database - 5NF
    • Database - BCNF

Advance Database

    • Database - File Organization
    • Database - Type Lock
    • Database - Transaction
    • Database - Key Type
    • Database - Relational Algebra
    • Database - Components
    • Database - Deadlock Detect
    • Database - Design Methodology
    • Database - Relational Operators
    • Database - Relational Calculus
    • Database - Lock Granularity
    • Database - Deadlocks Handling
    • Database - Concurrent Control
    • Database - Denormalization
    • Database - Starvation
    • Database - OODB
    • Database - Data Warehouse
    • Database - Fragmentation
    • Database - Data Replication
    • Database - Distributed
    • Database - Transparences
    • Database - ORDBMSS
    • Database - Data Mining
    • Database - Security
    • Database - DBTG
    • Database - OLAP
    • Database - Integrity
    • Database - Data Encryption
    • Database - Recover
    • Database - Data Protection

Some Other Advance Articls

  • Adv of Distributed DBMS
  • Homogeneous and Heterogeneous
  • Causes for Database Failure
  • DBMS Architecture
  • Features for Any DBMS
  • OLTP Systems Vs Data Warehousing
  • Data Warehousing Architecture

Other Links

  • DBMS - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW