Quick revision
The short answer
Because a list of flags was tuned for someone else's workload, heap size and JDK version, it can easily make our service slower, not faster. Many such flags are obsolete or removed in newer JDKs and cause warnings or even startup failures, explicit flags can switch off the adaptive behaviour that improves with every release, and without our own measurement nobody can tell later whether a flag still helps. The better approach is to start with defaults, measure, and add a flag only with a written reason and a measurement behind it.
What to remember
In this answer, we saw why a copied list of JVM flags is risky: the values were tuned for another workload and heap, many flags are obsolete or removed in modern JDKs and can block startup, explicit values switch off adaptive behaviour that improves every release, and without a measurement nobody can later judge them. The alternative is to start from current defaults, measure, change one thing at a time, and keep a flag only with a written reason.
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.
Because a list of flags was tuned for someone else's workload, heap size and JDK version, it can easily make our service slower, not faster. Many such flags are obsolete or removed in newer JDKs and cause warnings or even startup failures, explicit flags can switch off the adaptive behaviour that improves with every release, and without our own measurement nobody can tell later whether a flag still helps. The better approach is to start with defaults, measure, and add a flag only with a written reason and a measurement behind it.
Why this question is asked
Searching for how to make a Java service faster brings up long lists of JVM options presented as best practice. Pasting them into a deployment feels productive, and the consequences only show up months or years later as worse performance, odd memory use or a failed JDK upgrade. Interviewers ask this question to see whether we understand that tuning is specific to a workload and a release, and whether we have a disciplined alternative. In this answer, we will look at an example list, go through the four ways it goes wrong, and then describe the approach that works instead.
1A Typical Copied List
Here is the kind of list that circulates in old articles and gets pasted into a modern Spring Boot service running on JDK 21. Each line looked sensible to its original author, on their machine, with their workload, years ago.
On JDK 21 this list ranges from harmful to fatal. Some flags tune a collector that no longer exists, some no longer exist at all, and others fix sizes the JVM would choose better by itself. Let us take the problems one at a time.
2Problem 1: The Flags Were Tuned for a Different Workload
Tuning flags encode a trade-off for one specific situation. A young generation of 2 GB with -Xmn2g suited a service with a particular allocation rate and live data set. A MaxTenuringThreshold of 4 suited objects with a particular lifetime. Our service has a different heap, different object lifetimes and a different latency target. A fixed young generation size, for example, disables G1's main tuning mechanism: G1 normally resizes the young generation after every collection to meet its pause target, and -Xmn takes that control away. So a flag that helped someone else can make our pauses longer.
The same goes for the heap itself. -Xms8g -Xmx8g in a pod with a 6 GiB limit is not a tuning choice at all; it is a guaranteed OOM kill once the heap grows.
3Problem 2: Many Flags Are Obsolete or Removed
HotSpot retires flags through deprecation, obsolescence and finally expiry. The CMS collector was removed in JDK 14, so UseConcMarkSweepGC and its tuning flags either do nothing with a warning or are rejected outright, depending on the flag and the release. UseParNewGC and AggressiveOpts were retired as well, and PrintGCDateStamps was replaced by unified logging in JDK 9, so it is an unrecognized option on modern JDKs and the JVM refuses to start.
So a copied list can fail on the very first start, or worse, start with warnings that nobody reads, run with flags that do nothing, and then fail on the next JDK upgrade.
4Problem 3: Explicit Flags Switch Off Improvements
Each JDK release improves the defaults: G1 has become faster and more adaptive with almost every release, ZGC gained a generational mode, container detection was added, and metaspace handling improved. Defaults adapt to the environment; explicit values do not. Turning off adaptive sizing, fixing survivor ratios or pinning thread counts means the JVM keeps the values from an old article even after the runtime has learned to do better. Over a few upgrades, the gap between the default and the frozen setting grows, usually in favour of the default.
| Flag | On JDK 21 | Effect |
|---|---|---|
-XX:+UseConcMarkSweepGC | CMS removed in JDK 14 | warning or startup failure |
| -XX:+PrintGCDateStamps | replaced by -Xlog | Unrecognized VM option |
| -Xmn2g | valid | stops G1 adapting young size |
-XX:-UseAdaptiveSizePolicy | valid for Parallel GC only | no effect on G1, misleading |
| -Xms8g -Xmx8g | valid | OOM kill in a 6 GiB pod |
-XX:+DisableExplicitGC | valid | can delay direct buffer cleanup |
5Problem 4: Nobody Knows Whether a Flag Still Helps
Even a flag that was right when it was added needs evidence to stay. A copied flag has no measurement behind it at all, so a year later nobody on the team can say whether removing it would make things better or worse. People become afraid to touch the list, it grows, and the service ends up with dozens of options whose purpose is lost. The cost is not only performance but also every future upgrade, because each flag must be investigated.
Notice that this is a knowledge problem rather than a technical one. A flag without a reason is a small piece of untested code.
6The Approach That Works
Start with the defaults of a current LTS JDK, plus the few settings that make the JVM fit its environment, such as a heap percentage for the container and GC logging. Then measure under realistic load: latency percentiles, throughput, GC logs and a JFR recording. Only if a measurement shows a problem do we change something, one flag at a time, and keep it only if a second measurement shows it helps. Each kept flag gets a comment with its reason and a link to the measurement, so the next person can decide whether it still applies.
Most services never need more than this. When they do, the reason is written next to the flag, and it can be tested again on the next upgrade.
7Follow-up questions
Are all blog posts about JVM flags useless?
No. Good articles explain what a flag does and when it helps, and that is valuable for understanding. The mistake is copying the values without the measurement. Use the article to form a hypothesis, then test it on your own workload.
What if the service already has a copied list?
Remove flags in small groups on a canary, comparing latency, throughput and GC behaviour with the old list. Remove obsolete flags first, since they do nothing on the current JDK anyway, then the fixed sizes that override adaptive behaviour.
Is any flag safe to add without measuring?
Flags that make behaviour visible or safe, rather than tuned, are generally fine: GC logging, a heap dump on OutOfMemoryError, ExitOnOutOfMemoryError in an orchestrated environment, and a heap percentage that fits the container. They do not encode workload assumptions.
8Conclusion
In this answer, we saw why a copied list of JVM flags is risky: the values were tuned for another workload and heap, many flags are obsolete or removed in modern JDKs and can block startup, explicit values switch off adaptive behaviour that improves every release, and without a measurement nobody can later judge them. The alternative is to start from current defaults, measure, change one thing at a time, and keep a flag only with a written reason.
Open with
Mainly because tuning flags encode someone else's trade-offs. A list from a blog was tuned for their heap, their allocation rate, their object lifetimes and their JDK version, and our service has none of those.
Then, if they want more
For example, a fixed young generation with Xmn stops G1 from resizing the young generation to meet its pause goal, so it can make pauses worse. Second, a lot of those lists are old. They're full of CMS flags, and CMS was removed in JDK 14, plus things like UseParNewGC or PrintGCDateStamps, which was replaced by unified logging.
On a modern JDK those either do nothing with a warning or stop the JVM from starting with Unrecognized VM option. Third, defaults improve in every release, G1 itself, container detection, metaspace, and explicit flags freeze old values so we don't get those improvements.
And fourth, a copied flag has no measurement behind it, so a year later nobody knows if it still helps and everyone is afraid to remove it.
What I do instead is start with the defaults of a current LTS, add only the things that fit the environment, like MaxRAMPercentage and GC logging, measure under realistic load, and add a flag only when a measurement shows a problem it fixes.
Each flag gets a comment with the reason and the measurement, so it can be re-checked on the next upgrade.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 14, Java 9
- 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 "Why is it a bad idea to copy a list of JVM tuning flags from a blog post into your...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/0bad2241d9/