IT lexicon › Programming › Stamped lock

Stamped lock

Programming På svenska → Updated: 2026-11-16

A lock-free data structure that uses a version number (the "stamp") to detect conflicts instead of blocking readers or writers.

Stamped locks are an optimistic locking pattern introduced by Doug Lea. Readers acquire a stamp (version number), read data without acquiring any lock, and validate at the end that no writer modified the data. Writers use conventional locking. It is much faster than traditional read-write-locks when reads heavily outnumber writes, but requires that the read operation be idempotent and retryable. Java 8+ includes a production-grade implementation in java.util.concurrent.locks.StampedLock.

Stamped locks shine in read-heavy workloads where read-write-locks become a bottleneck. They require care: the reader must be prepared to retry the entire operation if validation fails.

← Back to the lexicon