Last night I was working on a little fun Clojure project that involved reading very large files. While reading and processing a 700MB file, my application crashed complaining that it had run out of memory. I had given it 500MB of RAM. What else does it need? Have you ever been in this situation where you are having Java memory issues and need to know exactly what’s going on? When this happens, your best friend is JMX and
jconsolecomes with the JDK so you already have it. To use these two together, you first need to start Clojure with the Java option
-Dcom.sun.management.jmxremote. Once the app is running you can run
jconsolewhich can be found in the
bindirectory of the JDK. This will open a window which will allow you to select the Java process to monitor. Once you select a process, you will see something like this:
This allows you to see the internals of the JVM as it is running. Armed with this information you should be able to figure out what is going on. After that, I'm sure you will go back to being mad at Java.
This is easy but I needed to make it a little easier. I updated my
cljscript to add the option above to Java when I pass it the
You can do a lot more with JMX and Clojure. If you wish to get into it in more detail, check out the jmx library in clojure.contrib by Stuart Halloway.