Quick revision
The short answer
I would first find the services with heavy uncontended synchronization, using profiling and JFR, then measure the effect before the upgrade by running them on Java 11 with -XX:-UseBiasedLocking and by load testing them on both Java 11 and Java 25 with production-like traffic. Where legacy synchronized collections sit on hot paths, I would replace them with unsynchronized or concurrent ones. The rollout itself is gradual, with canaries that compare latency and CPU per request, and the decision is based on the net effect, because most services gain more from other JDK improvements than they lose from one removed optimisation.
What to remember
In this answer, we saw why services using Vector, Hashtable, StringBuffer and synchronized utilities on hot single-threaded paths are the ones at risk when biased locking disappears. We find them with CPU profiles, JFR and a code scan, measure the isolated cost on Java 11 with -XX:-UseBiasedLocking and the real effect with production-like load tests on both JDKs, replace legacy synchronized collections where profiles point to them, and roll out gradually with canaries comparing latency and CPU per request. The decision is based on the net effect, which for most services is a gain.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would first find the services with heavy uncontended synchronization, using profiling and JFR, then measure the effect before the upgrade by running them on Java 11 with -XX:-UseBiasedLocking and by load testing them on both Java 11 and Java 25 with production-like traffic. Where legacy synchronized collections sit on hot paths, I would replace them with unsynchronized or concurrent ones. The rollout itself is gradual, with canaries that compare latency and CPU per request, and the decision is based on the net effect, because most services gain more from other JDK improvements than they lose from one removed optimisation.
Why this question is asked
An upgrade from Java 11 to Java 25 crosses fourteen releases of changes, and biased locking removal is one of the few that can make some code slower. Leading a fleet upgrade means turning that risk into numbers per service, instead of either ignoring it or treating it as a reason to stay on Java 11. Interviewers ask this to see whether we can plan measurement, mitigation and rollout across many services. In this answer, we will see why these services are the ones at risk, find them, measure the impact in two ways, reduce it in the code, roll out safely, and keep the whole picture in view.
1Why These Services Are the Ones at Risk
On Java 11, biased locking is on by default. An object locked repeatedly by one thread is biased to it, and later locks cost almost nothing. Vector, Hashtable, StringBuffer and synchronized utility classes lock on every call, so in a single-threaded hot loop they benefit most. On Java 25, biased locking is gone (disabled in JDK 15, removed afterwards), so each of those calls costs a compare-and-swap again.
Other locking changes arrive in the same jump: the new lightweight locking scheme replaced the legacy stack locking as the default in recent releases, and synchronized no longer pins virtual threads since JDK 24. These usually help, but they are changes, and the services that synchronize most are where they show up first. So our risk is concentrated in a few services with heavy uncontended locking on hot paths, not spread across the fleet.
2Finding the Services With Heavy Synchronization
JFR's monitor events, such as jdk.JavaMonitorEnter, record contended lock entries above a threshold, so they are good for finding contention. But the risk here is uncontended locking, which those events do not record. So we combine sources. A CPU profile, from JFR execution samples or async-profiler, shows time spent in methods such as Vector.add, Hashtable.get or StringBuffer.append on hot paths. A static scan of the code and dependencies counts uses of the legacy classes and of synchronized methods in hot modules.
The output is a short list: services where legacy synchronized classes show up prominently in CPU profiles. Those get the full measurement; the rest of the fleet follows the normal upgrade path.
3Measuring the Impact Before Switching
We have a neat trick for the biased locking part: Java 11 still supports -XX:-UseBiasedLocking. Running a load test on Java 11 with and without that flag isolates exactly the cost of losing biased locking, with nothing else changed. If the difference is within noise, biased locking is not a concern for that service.
Then we run the real comparison: the same service, the same build, under production-like traffic on Java 11 and on Java 25, measuring throughput, p50, p99 and p99.9 latency, and CPU per request. Production-like matters, because a microbenchmark of one class says little about a whole request path with I/O, GC and caching.
| Run | Throughput | p99 latency | CPU per request |
|---|---|---|---|
| Java 11, default | 4,000 | 48 ms | 1.00 (baseline) |
Java 11, -XX:-UseBiasedLocking | 3,880 | 50 ms | 1.03 |
| Java 25, default | 4,300 | 41 ms | 0.94 |
| Java 25, legacy collections replaced | 4,450 | 39 ms | 0.91 |
4Reducing the Risk in the Code
Where a profile shows legacy synchronized classes on a hot path, the cheapest fix is usually to replace them. If the data is confined to one thread, Vector becomes ArrayList, Hashtable becomes HashMap and StringBuffer becomes StringBuilder, and the locks disappear entirely. If the data really is shared, ConcurrentHashMap or other concurrent collections usually perform better than the old fully synchronized ones under any contention.
These changes are mechanical but not free: we must check that the object really is thread-confined before removing synchronization, because the old class may have been hiding a race. So each replacement gets a short review of who can reach the object, and the service's tests run on both JDKs. This work also pays off on Java 11, so it can start before the upgrade.
5Rolling Out Gradually With Canaries
For each service, the upgrade goes out to a canary, a small share of instances or traffic, say 5 percent, running Java 25 next to the Java 11 instances. We compare the two groups over at least a full daily traffic cycle on the same dashboards: p99 latency, error rate, CPU per request and GC pause times. If the canary is within the agreed threshold, for example no more than 5 percent worse on p99 and CPU per request, we widen to 25, 50 and 100 percent.
The services from our risk list go later in the programme, after the lower-risk ones have shaken out general upgrade problems such as removed APIs, changed defaults and library compatibility. That way, if a locking-related regression appears, it is not mixed up with unrelated issues.
- Heavy synchronization in the profile?YesMeasure with -XX:-UseBiasedLocking on 11NoNormal upgrade path
- Load test on Java 11 and Java 25throughput, p99, CPU per request
- Regression beyond threshold?YesReplace legacy collections, retestNoCanary at 5 percent
- Canary matches over a daily cycle?YesWiden to 25, 50, 100 percentNoRoll back and investigate
4 steps in order. Play them, or step through them one at a time.
6Measuring the Net Effect
It is easy to focus on biased locking because it is the change we know is negative. But between Java 11 and Java 25 the JIT, the garbage collectors, string handling, startup and many libraries have improved, and most services get faster overall. The decision for each service should therefore be based on the net effect measured end to end, not on one feature.
If a service still regresses after the code fixes, we treat it like any other performance issue: profile on Java 25, find what got slower, and fix that. There is no supported way to bring biased locking back, so staying on Java 11 for it would only postpone the work while missing security updates and improvements.
7Follow-up questions
Can we turn biased locking back on in Java 25?
No. The implementation was removed, and the UseBiasedLocking flag is obsolete in recent JDKs, so the JVM either ignores it with a warning or refuses to start, depending on the version. Any mitigation has to be in the code or in other tuning.
Why not rely on JFR monitor events alone?
Because they record contended monitor entries, usually above a duration threshold such as 20 ms. Biased locking only helped uncontended locks, which those events do not show. CPU profiles that reveal time in synchronized legacy methods are the better signal for this risk.
How many services would you expect to need code changes?
Usually very few. Most modern Spring services use ArrayList, HashMap and StringBuilder and spend their time in I/O, so the loss of biased locking is within measurement noise. The point of the assessment is to find the few exceptions early, not to change every service.
8Conclusion
In this answer, we saw why services using Vector, Hashtable, StringBuffer and synchronized utilities on hot single-threaded paths are the ones at risk when biased locking disappears. We find them with CPU profiles, JFR and a code scan, measure the isolated cost on Java 11 with -XX:-UseBiasedLocking and the real effect with production-like load tests on both JDKs, replace legacy synchronized collections where profiles point to them, and roll out gradually with canaries comparing latency and CPU per request. The decision is based on the net effect, which for most services is a gain.
Open with
I would treat it as a measurement problem, focused on the few services where it matters. The risk is that Java 11 biases uncontended locks, so Vector, Hashtable and StringBuffer calls in hot single-threaded loops are almost free, while on Java 25 biased locking is gone and each call costs a CAS again, and the locking implementation itself changed too.
Then, if they want more
First, I would find the services with heavy synchronization: CPU profiles from JFR or async-profiler showing time in those legacy methods, plus a code scan. JFR monitor events help for contention, but they do not show uncontended locks, which is what biasing helped.
Then I would measure the isolated effect on Java 11 by running a load test with -XX:-UseBiasedLocking, and the real effect by load testing the same build on Java 11 and Java 25 with production-like traffic, looking at throughput, p99 and CPU per request.
Where legacy collections are on hot paths and the data is thread-confined, I would replace them with ArrayList, HashMap and StringBuilder, or concurrent collections if shared, after checking they really are confined. The rollout would be gradual with canaries, comparing latency and CPU per request over a daily cycle, with the higher-risk services later.
And I would judge by the net effect, since most services get faster on Java 25 overall.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 11, Java 25, Java 15, Java 24
- 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.
- Official documentation
- java.util.concurrent, package documentation, JLS chapter 17, Threads and Locks
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 "You are leading a fleet upgrade from Java 11 to Java 25. Some older services rely...": https://scrivio-interview-library.netlify.app/java/synchronization/0635e7e262/