Use -Xmx to specify the maximum heap size.Use -Xms to specify the initial Java heap size.Use -Xss to set the Java thread stack size.
How do I reduce Java memory usage?
- Maintain a consistent heap size allocation. Make -Xms equal to -Xmx.
- Reduce the amount of discarded objects (garbage) E.g. buffer less Kafka messages.
- A little bit GC goes a Long way.
Why does Java consume so much memory?
Java is also a very high-level Object-Oriented programming language (OOP) which means that while the application code itself is much easier to maintain, the objects that are instantiated will use that much more memory.