How do you detect low memory situations in a Java virtual machine?

Recently, I am getting some OutOfMemory errors. Is it possible to detect in advance when the virtual machine is still working on memory? In other words, to proactively deal with OutOfMemory errors before they actually happen?

+3
source share
3 answers

Java (starting with Java 5) now has a standard JMX bean that can be used to receive low memory notifications. See java.lang.management.MemoryMXBean.

+6
source

I suggest that the best question is: "Why does my application run out of memory?"

, , JVM ; (, , .)

  • , 24x7x365?
  • ?

/, , .

+3

Take a look at the freeMemory Runtime method (see http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html for details)

In short: do

Runtime.getRuntime().freeMemory()
+2
source

Source: https://habr.com/ru/post/1698700/


All Articles