lock-striping | Coarse Grained Synchronization vs Lock Striping https
kandi X-RAY | lock-striping Summary
kandi X-RAY | lock-striping Summary
A simple repository to demonstrate the fact that how well a fine-grained synchronized concurrent data structure performs compared to its coarse-grained counterpart.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Resize buckets
- Acquires all locks
- Release all locks
- Gets the value associated with the given key
- This method generates a hash code for the given key
- Find the bucket for the given entry
- Benchmarks for a coarse grained executor
- Perform a workload on the cluster
- Tries to acquire a lock for the given entry
- Returns the lock for the given entry
- Adds an entry to the map
- Attempts to release the lock for the given entry
- Entry point
- Benchmark for extracting lock
- Acquires an entry
- Unlock entry
- Increases the size of the hash table
- Compares this map with the specified key
- Removes the specified key from the map
- Returns a random key
lock-striping Key Features
lock-striping Examples and Code Snippets
Community Discussions
Trending Discussions on lock-striping
QUESTION
I have been reading through Concurency in Practice
by Brian Goetz.
In the chapter about Lock Striping it is written that ConcurrentHashMap
uses 16 buckets to improve multithreaded access by many threads :
Lock splitting can sometimes be extended to partition locking on a variablesized set of independent objects, in which case it is called lock striping. For example, the implementation of ConcurrentHashMap uses an array of 16 locks, each of which guards 1/16 of the hash buckets; bucket N is guarded by lock N mod 16.
I have read those questions :
Need simple explanation how “lock striping” works with ConcurrentHashMap
However those answers are valid for Java version <= 7.
For Java 8+ the behaviour seems to be changed significantly. For Java 8+ it seems that that the lock is acquired not for a Segment but for particular Node in table (transient volatile ConcurrentHashMap.Node[] table;
). For example for the putVal
operation :
ANSWER
Answered 2019-Jul-28 at 10:35What is the cause of such significant change in ConcurrentHashMap implementation?
To reduce memory footprint (one of the reasons).
We do not want to waste the space required to associate a distinct lock object with each bin, so instead use the first node of a bin list itself as a lock. Locking support for these locks relies on builtin "synchronized" monitors.
openjdk > jdk8 >
java.util.concurrent.ConcurrentHashMap.java
> Line 314
If class
Segment
is unused and also field likeDEFAULT_CONCURRENCY_LEVEL
is also unused - why not get rid of it from implementation - is it for some historical reasons?
To ensure serialization compatibility.
We also declare an unused
Segment
class that is instantiated in minimal form only when serializing.openjdk > jdk8 >
java.util.concurrent.ConcurrentHashMap.java
> Line 486
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lock-striping
You can use lock-striping like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the lock-striping component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page