Category Archives: debugging

Print stacktraces for all threads on shutdown

If your microservice stops responding from time to time, and they only way out is to kill it with SIGINT or SIGTERM then adding a shutdown hook might be the way to go. Do note that this will not work if you kill the process with SIGKILL (-9), cause that will result in an unclean shutdown.

Some of this code is heavily influenced by Print all of the thread’s information and stack traces : Exception « Development « Java Tutorial. But has been translated into Scala, and cleaned up a little.

The output would look something like this

 

DTrace;ing the JVM, useful tips

I am using DTrace from time to time and it is really nice, you can do a lot with it.

This page is mostly a reminder to myself cause there are tons of pages out there if you google it, but I figured that why not share the knowledge 🙂

List all Probes available in a process

 List all probes that has to do with the JAVA JVM Hotspot

dtrace -l | grep hotspot

Figure out WHO initiated the Garbage Collection (GC)

dtrace -n ‘hotspot$target:::gc-begin { jstack(); }’ -p 25736

JVM Probes

http://docs.oracle.com/javase/6/docs/technotes/guides/vm/dtrace.html

Figure out what objects are being allocated using DTrace

http://prefetch.net/blog/index.php/2007/10/31/using-the-dtrace-hotspot-provider-to-observe-java-object-allocations/

JVM: Unable to open door

The jinfo command needs to be run by the user the JVM runs as.