Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you detect low memory situations within the java virtual machine?

I've been getting some OutOfMemory errors lately in my application. Is it possible to detect ahead of time when the virtual machine is running low on memory? In other words to preemptively deal with OutOfMemory errors before they actually occur?

like image 661
Obediah Stane Avatar asked Jun 25 '26 17:06

Obediah Stane


1 Answers

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

like image 52
Darron Avatar answered Jun 28 '26 07:06

Darron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!