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 April 2026
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 305 contents
https://gainjavaknowledge.medium.com/10-java-performance-mistakes-senior-developers-still-make-96a614864abb
10 Java Performance Mistakes Senior Developers Still Make (Page last updated April 2026, Added 2026-04-28, Author Sumit Pal Singh, Publisher Gain Java Knowledge). Tips:
- Avoid Java Streams in hot paths when allocation, lambda overhead, or CPU cache locality matter; use simple loops for performance-critical code.
- Warm up JVM code before measuring performance because early runs may be interpreted while later runs benefit from JIT-compiled machine code.
- Use JMH with warm-up iterations instead of timing cold code manually.
- Avoid unnecessary object creation inside tight loops, reuse objects where appropriate, prefer primitives over boxed wrappers when possible, and avoid allocations that add no value.
- Prefer concurrent collections such as ConcurrentHashMap over globally synchronized wrappers when multiple threads need shared access.
- Use CopyOnWriteArrayList only for read-heavy workloads with infrequent writes, because writes copy the backing array.
- Reduce database queries with joins, batch queries, or prefetching related data. Fetch only the database columns needed for the operation to reduce I/O, memory use, and object hydration cost. Add appropriate database indexes for frequently filtered, joined, or sorted columns.
- Cache frequently accessed data when the data is stable enough and cache invalidation rules are clear.
- Use a connection pool, tune database pool size carefully; too small creates bottlenecks, while too large wastes resources and can overload the database.
- Avoid blocking request-handling threads in high-concurrency systems with blocking I/O, or slow external API waits.
- Avoid string concatenation in logging statements; use parameterized logging such as log.info("Processing user: {}", user).
- Use appropriate log levels so high-volume diagnostic logs can be disabled in production.
- Compare optimization targets by impact; saving milliseconds in Java code won't matter if a database query or external call dominates latency.
https://dzone.com/articles/systematic-approach-to-java-performance-debugging
Debugging Performance Regressions in High-Scale Java Web Services: A Systematic Approach (Page last updated November 2025, Added 2026-04-28, Author Karthik Puthraya, Publisher DZone). Tips:
- Use the order of alerts as a first pass. If latency rises before CPU, suspect I/O waits or downstream dependencies. If CPU rises before heap growth, suspect allocation churn or retained objects.
- Build a performance incident timeline from the first metric that changed, then compare CPU, heap, GC, threads, request latency, downstream waits, and disk alerts to separate causes from symptoms.
- Watch heap after GC: if usage does not return to baseline, investigate object retention or leaks.
- Use short, scoped Java Flight Recorder captures in production to inspect allocation hotspots, lock contention, and hot methods with low overhead.
- Analyze retained sets in heap dumps to find the references keeping supposedly short-lived objects alive.
- Capture multiple thread dumps a few seconds apart to distinguish threads blocked on socket reads, synchronization, or application hot paths.
- Add deadlock detection with ThreadMXBean.findDeadlockedThreads() and feed it into monitoring for early visibility into locking regressions.
- Track pooled threads against configured limits; when busy threads approach the cap, new requests queue and latency stretches.
- Use structured, parameterized logging to avoid eager string construction and temporary object retention on hot request paths.
- Consider bulkheads around slow downstream services so one dependency cannot consume all request-handling capacity.
- Tune GC only after distinguishing leaks from allocation churn; collector changes and pause goals help most when memory is being allocated rapidly but not leaked.
- For G1GC, tune options such as MaxGCPauseMillis and InitiatingHeapOccupancyPercent to reduce pause times under load.
- Validate fixes under realistic load and watch tail latency, GC pauses, thread saturation, and request rejection rates after changes.
- Integrate profiling into CI/CD so allocation, GC, and latency regressions are caught before reaching production.
https://itnext.io/5-proven-techniques-for-ultra-fast-low-latency-trading-systems-in-java-c0837958ecd8
5 Proven Techniques for Ultra-Fast, Low-Latency Trading Systems in Java (Page last updated December 2025, Added 2026-04-28, Author Gavin F., Publisher ITNEXT). Tips:
- Use primitive data types where structures or less efficient data types can be mapped into them. Eg use fixed-point `long` prices in hot comparison paths instead of `BigDecimal`, and format decimals only at the edge.
- For small bounded datasets, search an array instead of using maps, for array's better cache locality.
- Replace LinkedList with preallocated fixed size ring buffers to reduce node allocation and pointer chasing.
- Use bitwise AND rather than modulus, eg power-of-two ring capacity `(index + 1) & (capacity - 1)` instead of `%`.
- Use object pools for hot objects where allocation and GC costs show up in measurements.
- A single-threaded engine per execution path with a front message queue can avoid synchronization in the matching path making it very efficient.
- Use JMH to verify changes before applying those low-latency data-structure changes.
- Choose the right data structure; don't forget memory allocation and GC impact; leverage CPU native operations (such as primitive data type and bitwise operations).
Jack Shirazi
Back to newsletter 305 contents
Last Updated: 2026-04-29
Copyright © 2000-2026 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/newtips305.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us