Monday, July 12, 2010

Watching a Java app die!


When you start living with Java, and extend that to eating and drinking java you start realizing amazing similarities between the language/paradigm and life. You start seeing java as a living organism which breaths and eats.

Once you hook up a java application for a monitoring tool like JConsole, you start seeing wondrous things. Analogically speaking this is similar to hooking up a person to an ECG machine. Once you get to analyze how the heap space keeps on increasing and how the garbage cleaner frees up memory from time to time it really starts looking like the ECG output. As a part of my geeky investigations, I felt like checking out whether I could recreate the ECG representation of a dying person on the JConsole using a dying Java program.
So, I chose one app which was throwing out of memory exceptions randomly, and decided to crank up the environment to the max and let the app run with probably the most resourceful environment. So, I turned on the –XX:+AggressiveHeap option which greedily expands the heap space and sets other relevant parameters. Then I also turned off the overload detection for the garbage collector. This latter was done by setting the -XX:+UseGCOverheadLimit option. This evaluates the proportion of time spent on GC and if it is significantly high, throws an out of memory error since it is very likely that it will run out of memory anyway.
After firing up the application, the awesome started to happen. I could see how the application started choking for life, until the heap space could not be expanded anymore, and the GC could not clean up anything further. After a tough battle, the application just died…!
Have a look at the JConsole output below.


Isn’t it fascinating? :)
FYI, here’s a list of VM options which you might not try out everyday.
Long live Java!!!


1 comment:

SanJ Wijeratne said...

Good Stuff Mate, Really felt like trying it after reading your "geeky investigations" :P