Direkt zum Hauptbereich

Posts

Video Specials

Java concurrency: StampedLock.

StampedLock was introduced in Java 8 and has been one of the most important features of the concurrent family. This is to support the Read/Write Lock, as RWLock got introduced way back in Java 5, which is facing severe starvation. Sometimes, we need better control over synchronization and to achieve this, we need a separate lock for read and write access. Thankfully, Java introduced ReentrantReadWriteLock under the java.util.concurrent.locks package, which provides an explicit locking mechanism. In ReadWrite Locking policy, it allows the read lock to be held simultaneously by multiple reader threads, as long as there are no writers, and the write lock is exclusive. But it was later discovered that ReentrantReadWriteLock has some severe issues with starvation if not handled properly (using fairness may help, but it may be an overhead and compromise throughput). For example, a number of reads but very few writes can cause the writer thread to fall into starvation. Make sure to analyze your …

Aktuelle Posts