Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

What was biased locking, why was it disabled by default in JDK 15 (JEP 374) and later removed, and who might notice?

Biased locking let HotSpot bias an object to the first thread that locked it, so that thread's later locks and unlocks needed no atomic instruction at all. When another thread arrived, the bias had to be revoked, which was expensive and often needed a safepoint. JEP 374 disabled it by default in JDK 15 because modern code rarely uses always-synchronized classes such as Vector and Hashtable, atomic instructions had become much cheaper, and the complex implementation was blocking other runtime work; it was removed in a later release. Applications heavy on uncontended legacy synchronized collections are the ones that might notice a small regression.

Why this question is asked

Biased locking is a good example of an optimisation that made perfect sense when it was introduced and became a burden later. Understanding why it existed and why it went tells us a lot about how JVM performance work trades speed for complexity, and it matters in practice when we upgrade older services. Interviewers ask about it to check that we know what the JVM did for uncontended locks and who might be affected by its removal. In this answer, we will recap the cost of an uncontended lock, see how biasing avoided it, look at the expensive revocation step, go through the reasons for removal, and identify who might notice.

1A Quick Recap: What an Uncontended Lock Costs

Even when no other thread wants a lock, entering synchronized needs an atomic compare-and-swap (CAS) on the object's header to record the owner, and leaving needs another atomic step. A CAS is a CPU instruction that reads, compares and writes memory as one indivisible action, and it forces ordering with other memory operations.

Around the time biased locking was introduced in Java 6, a CAS on common CPUs could cost tens to around a hundred cycles. Code at the time used Vector, Hashtable and StringBuffer everywhere, and their methods are all synchronized, so a loop over a Vector paid a CAS pair for every element even in a single-threaded program.

2How Biased Locking Avoided the CAS

The observation behind biased locking was that most objects are only ever locked by one thread. So the first time a thread locked an object, HotSpot wrote that thread's id into the object's mark word with one CAS, biasing the object to it. From then on, when the same thread locked the object again, the JVM only had to check that the header still named it, an ordinary read and compare, with no atomic instruction. Unlocking did nothing at all.

For a single-threaded loop over a Vector, that turned a million CAS pairs into a million cheap checks, which was a real win on the hardware of the time.

Java
Vector<Integer> v = new Vector<>();
for (int i = 0; i < 1_000_000; i++) {
v.add(i); // synchronized: with biasing, no CAS after the first call
}
// JDK 8 or 11: biased by default (after a startup delay)
// JDK 15+: -XX:+UseBiasedLocking needed (deprecated), later the flag is gone

3The Expensive Part: Revocation

The trouble started when a second thread locked a biased object. The bias had to be revoked: the JVM had to find out whether the biased thread was currently inside a synchronized block on the object and, if so, rewrite that thread's stack so it looked like a normal lightweight lock. Because another thread's stack was being changed, this usually required stopping that thread at a safepoint, and often all threads.

HotSpot added heuristics such as bulk rebiasing and bulk revocation per class to reduce the cost, but revocation remained a pause that could show up in latency, especially in programs where objects are created by one thread and then used by others, such as a producer handing items to a pool of workers.

Step throughThe life of a biased lock
  1. First lock by thread Tone CAS writes T's id into the header
  2. T locks againheader still says T: no CAS
  3. Another thread U wants the lock?
    YesRevoke the biasNoStay biased to T
  4. Revocationoften a safepoint; T's stack may be rewritten
  5. Object uses normal locking from now on

5 steps in order. Play them, or step through them one at a time.

4Why It Was Disabled and Removed

JEP 374 gave three reasons. First, the gains had shrunk. Modern code uses ArrayList, HashMap and StringBuilder, which are not synchronized, or concurrent collections such as ConcurrentHashMap that avoid locks on most reads, so far fewer hot paths take uncontended monitors. Second, CPUs had made atomic instructions much cheaper, so the cost biased locking saved was smaller. Third, the implementation was large and intricate, it touched the object header, the interpreter, the compilers and safepoints, and it made other improvements in the synchronization and runtime code harder.

So JDK 15 disabled it by default and deprecated the -XX:+UseBiasedLocking flag, which let users turn it back on while the effect was measured. With few reports of significant regressions, the code was removed in a later release (JDK 18), and the flag no longer has any effect.

5Who Might Notice

The applications that might see a difference are those that still lock the same objects repeatedly from one thread on hot paths: heavy use of Vector, Hashtable, StringBuffer, Collections.synchronizedMap, or older libraries built on them. For them each lock now costs a CAS again. In most measurements the regression is small, a few percent at most on those paths, and often hidden by other improvements in newer JDKs.

Applications with heavy multi-threaded handoff may even get faster, because revocation pauses disappear. The way to know is to measure: on Java 11 we can run with -XX:-UseBiasedLocking to preview the effect before upgrading, and replace legacy synchronized collections on hot paths with ArrayList, HashMap or StringBuilder where the data is confined to one thread.

6Follow-up questions

Why did biased locking have a startup delay?

During JVM startup, many objects are locked by several threads, so biasing them would just cause revocations. HotSpot therefore enabled biasing only after a few seconds (BiasedLockingStartupDelay, 4 seconds by default in JDK 8), so short benchmarks sometimes behaved differently from long-running servers.

Does the identity hash code interact with biased locking?

Yes. The mark word could hold either a bias or the identity hash code, not both. Calling System.identityHashCode or the default hashCode on a biased object forced the bias to be revoked, one more reason the scheme was complicated.

Is uncontended locking slow now?

No. It costs a CAS, which on modern CPUs is cheap, and the newer lightweight locking keeps that path fast. Uncontended locking is rarely a bottleneck in modern applications; contention is.

7Conclusion

In this answer, we saw that biased locking let an object be biased to the first thread that locked it, so that thread could re-lock without any atomic instruction, which helped the heavily synchronized collections of the Java 6 era. The cost was revocation when another thread arrived, often at a safepoint, plus a complex implementation. Because modern code uses fewer always-synchronized classes, atomics became cheaper and the code blocked other runtime work, JEP 374 disabled it by default in JDK 15 and it was later removed. Only applications heavy on uncontended legacy synchronized collections might notice a small regression, and we can measure that with -XX:-UseBiasedLocking on older JDKs.

What to say in the interviewAbout 80 seconds aloud

Open with

Biased locking was a HotSpot optimisation for uncontended locks. Normally every lock and unlock needs an atomic compare-and-swap on the object header. With biasing, the first thread that locked an object wrote its id into the header, and after that, when the same thread locked it again, the JVM only checked the header, with no atomic instruction, and unlock did nothing.

Then, if they want more

That helped a lot when code used Vector, Hashtable and StringBuffer everywhere and CAS was expensive. The problem was revocation: when another thread wanted the lock, the JVM had to remove the bias, possibly rewriting the owner's stack, which usually needed a safepoint and caused pauses.

JEP 374 disabled it by default in JDK 15 and deprecated the flag, and it was removed in a later release. The reasons were that modern code rarely uses those always-synchronized classes, atomic instructions became much cheaper, and the implementation was complex and got in the way of other improvements to locking and the runtime.

Who might notice: applications that still use legacy synchronized collections heavily on hot single-threaded paths, and the regression is usually small. On Java 11 I would measure with -XX:-UseBiasedLocking before upgrading, and replace those collections where the data is confined to one thread.

About this answer

Last updated
12 November 2026
Versions it names
Java 15, Java 6, Java 8, Java 11
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What was biased locking, why was it disabled by default in JDK 15 (JEP 374) and later...": https://scrivio-interview-library.netlify.app/java/synchronization/4fd16fe86b/