Embark on a journey into the depths of java.lang.OutOfMemoryError as we unravel its complex nature. Discover the nine distinct faces of this memory-related challenge and gain valuable insights into their unique causes and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
2. Does Java process memory utilization go beyond –Xmx?
2
–XX:MaxMetaspaceSize
-Xmx
Young Old
Metaspac
e
Threads JNI misc
GC
Direct
Buff
Code
Cach
e
Heap Memory Native Memory
Java Process Memory
6. 6
GC Behavior of a Healthy Application
- Full Garbage Collection Event
7. 7
GC Behavior of Acute Memory Leak
- Full Garbage Collection Event
8. 8
GC Behavior when there is a Memory Leak
- Full Garbage Collection Event
9. 9
How to study GC Behavior?
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<file-path>
Till Java 8
-Xlog:gc*:file=<file-path>
From Java 9
Enable GC logs (always)
Almost zero overhead
26. 26
Unable to create new native threads
Young Old
Metaspac
e
JNI misc
GC
Direct
Buff
Code
Cach
e
Heap Memory Native Memory
JVM Memory
27. 27
Real Case Study
Slowdown in a Major Financial Institution’s Middleware
http://fastthread.io/my-thread-report.jsp?p=c2hhcmVkLzIwMTcvMDMvMTQvLS10aHJlYWREdW1wLTIudHh0LS0xMi0yOC0zMw==&s=t
28. 28
OutOfMemoryError: Unable to create new native
threads
Causes
1. Threads are leaking
Solutions
1. Fix thread leak
2. Increase the Thread Limits Set
at Operating System(ulimit –u)
3. Reduce Java Heap Size
4. Kills other processes
5. Increase RAM capacity
6. Reduce thread stack size (-Xss).
Note: can cause
Artifacts
1. Thread Dump
Tools
1. FastThread
2. Text Editor
29. 29
Direct buffer memory
Young Old
Metaspac
e
Threads JNI misc
GC
Code
Cach
e
Heap Memory Native Memory
JVM Memory
Becoming Prevasive in modern Spring Boot Frameworks
30. 30
OutOfMemoryError: Direct buffer memory
Causes
1. Increase(or Leak) in direct buffers
usage
a. java.nio package
b. Moving from Spring
RestTemplate to WebClient
c. Image Processing Libraries
d. Networking Libraries
e. Some JDBC Drives
Solutions
1. Fix Memory Leak code
2. Increase -
XX:MaxDirectMemorySize
3. Upgrade to Java 17 (There some
issues in Java 11)
Artifacts
1. App Log or Std error
2. Native Memory Tracking
Tools
39. Ram Lakshmanan ram@tier1app.com
@tier1app https://www.linkedin.com/company/ycrash
This deck will be published in:
https://blog.heaphero.io
If you want to learn more …
39
THANK YOU
FRIENDS