Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Concurrency, Threading, GC, Advanced Java and more ...
Tips September 2025
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 298 contents
https://foojay.io/today/performance-best-practise-no-1-optimize-database-operations/
Performance Best Practise No. 1: Optimize Database Operations (Page last updated June 2025, Added 2025-09-24, Author Ondro Mihalyi, Publisher foojay.io). Tips:
- Set the connection pool max size to match the maximum connections allowed by your database.
- Ensure the thread pool max size is usually larger than the connection pool max size.
- Configure connection idle timeouts shorter than the database-side timeouts to avoid stale connections.
- Use prepared statements and reuse them for repeated queries to avoid unnecessary SQL parsing.
- Enable caching to reuse statements and reduce parsing overhead.
- Enable JDBC batching or JPA batching to efficiently execute multiple SQL operations together.
https://www.youtube.com/watch?v=renTMvh51iM
Java 21 -> 25: Performance and Runtime Enhancements (Page last updated September 2025, Added 2025-09-24, Author Billy Korando, Publisher Inside Java). Tips:
- Between JDK 21 and 24, virtual threads had a problem: when blocking in synchronized blocks/methods, they didn't release their lock back to the platform thread. This was fixed in JDK 24 (JEP 491 - synchronized virtual threads without pinning).
- Compared to JDK 21, JDK 25 has startup time improvements and throughput gains.
- JDK 25 may use more heap memory than JDK21 if using defaults, but when the heap is capped, it uses less. If memory looks high, set a heap size cap to guide the JVM.
- Compact Object Headers moved the header size from 128-bit object headers to 64-bit headers (saves heap space, reduces GC pressure, lower latency). Enable with: -XX:+UseCompactObjectHeaders.
- From JDK 25 onward, only generational ZGC exists, the single-generation mode has been removed - and is better for both CPU and memory in nearly all cases.
- New for JFR in JDK 25: reportOnExit automatically opens a JFR view (e.g., GC pauses) when the JVM shuts down; cooperative sampling; method timing & tracing which lets you trace/timestamp method calls via config (no code changes). Example: `-XX:StartFlightRecording=method-timing=simplejpa.repository.MyMethod` and `-XX:StartFlightRecording=filename=myapp.jfr,reportOnExit -jar`.
https://www.youtube.com/watch?v=dSLe6G3_JmE
ZGC - Paving the GC On-Ramp (Page last updated July 2025, Added 2025-09-24, Author Erik Osterlund, Publisher JavaOne). Tips:
- From Java 25, ZGC should be used with no other GC or heap flags - not even Xmx, only -XX:+UseZGC! Most options are automatically adjusted up and down or configured as needed during runtime including: heap sizing, GC thread counts, NUMA, large pages.
- From Java 25 when using ZGC don't apply Xmx, Xms, AlwaysPreTouch, unless you've tried the simplest configuration and have identified specific GC related issues.
- When using ZGC only set a heap cap if your environment requires strict memory limits, otherwise let ZGC size automatically; and enable monitoring (e.g., JFR, GC logs) to observe CPU vs. memory balance. This will identify if ZGC automatic adaptations are not working for your app.
- From Java 25, you only need UseZGC, nothing else. Examples of XX flags you no longer need: InitialHeapSize MinHeapSize MaxHeapSize SoftMaxHeapSize AlwaysPreTouch UseLargePages NewSize MaxNewSize InitiatingHeapOccupancyPercent MaxTenuringThreshold ConcGCThreads ParallelGCThreads MaxGCPauseMillis ParallelRefProcEnabled ExplicitGCInvokesConcurrent GCLockerRetryAllocationCount UseNUMA AggressiveHeap UseAdaptiveGenerationSizePolicyAtMajorCollection UseAdaptiveSizePolicyFootprintGoal.
Jack Shirazi
Back to newsletter 298 contents
Last Updated: 2025-12-25
Copyright © 2000-2025 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/newtips298.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us