I am working on a Java code, I need to implement threading in it. I was going through JAVA 8 API and I come to know about Stamped Locks. Can anyone tell me why to use StampedLocks in multithreading?
Thanks in advance.
StampedLock is an alternative to using a ReadWriteLock (implemented by ReentrantReadWriteLock). The main differences between StampedLock and ReentrantReadWriteLock are that:
So if you have a scenario where you have contention (otherwise you may as well use synchronized
or a simple Lock
) and more readers than writers, using a StampedLock can significantly improve performance.
However you should measure the performance based on your specific use case before jumping to conclusions.
Heinz Kabutz has written about StampedLocks in his newsletter and he also made a presentation about performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With