Skip to main content

What is Lock splitting technique in Java? Which technique is used in ReadWriteLock class for reducing Lock contention in Java? Java interview

 


What is Lock splitting technique?

Lock splitting is a technique to reduce Lock contention in multithreading. 

It is applicable in scenario when one lock is used to synchronize access to different aspects of the same application.

Sometimes we put one lock to protect the whole array. There can be multiple threads trying to get the lock for same array. 

This single lock on array can cause Lock contention among threads. 

To resolve this we can give one lock to each element of the array. Or we can use modulus function to assign different locks to a small group of array elements. 

In this way we can reduced the chance of Lock contention. This is Lock splitting technique.



Which technique is used in ReadWriteLock class for reducing Lock contention?

ReadWriteLock uses two locks. One lock for read-only operations, another lock for write operations.

Its implementation is based on the premise that concurrent threads do not need a lock when they want to read a value while no otherthread is trying to write.

In this implementation, read-only lock can be obtained by multiple threads. 

And the implementation guarantees that all read operation will see only the latest updated value as soon as the write lock is released.

Comments

Popular posts from this blog

AirBnB Infographic Journey to IPO

  Full Post at  https://techpomelo.com/2020/10/infographics-airbnb-milestone-journey-to-ipo/

Defination of the essential properties of operating systems

Define the essential properties of the following types of operating sys-tems:  Batch  Interactive  Time sharing  Real time  Network  Parallel  Distributed  Clustered  Handheld ANSWERS: a. Batch processing:-   Jobs with similar needs are batched together and run through the computer as a group by an operator or automatic job sequencer. Performance is increased by attempting to keep CPU and I/O devices busy at all times through buffering, off-line operation, spooling, and multi-programming. Batch is good for executing large jobs that need little interaction; it can be submitted and picked up later. b. Interactive System:-   This system is composed of many short transactions where the results of the next transaction may be unpredictable. Response time needs to be short (seconds) since the user submits and waits for the result. c. Time sharing:-   This systems uses CPU scheduling and multipro-gramming to provide econ...