IT lexicon › Programming › Double-checked locking

Double-checked locking

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

A pattern where you check a condition without locking, and only acquire the lock if the check fails, to optimize lazy initialization.

Double-checked locking tries to combine performance (the first check is lock-free) with correctness (the second check under lock). The pattern was broken in Java before Java 5, when the memory consistency rules were strengthened. It appears often in connection pooling and singleton implementations, but requires volatile variables to work correctly—without them, a thread may see a partially-initialized object. Modern languages with stronger memory models handle this better, but the pattern remains fundamentally subtle.

← Back to the lexicon