Thursday, 9 May 2013

The dumpStack code monster - alive and scary

Tracing through some critical code in a core application I stumbled across the following:

    public boolean process(PSEvent event) {
        return process(event, true);

    public boolean process(PSEvent event, boolean markAsProcessed) {
        boolean success = false;

        try {
            // Do some stuff...

        } catch (Exception e) {
            // Do some other stuff...
            success = false;

        return success;

The javadoc on Thread.dumpStack() is very helpful:
Prints a stack trace of the current thread to the standard error stream. This method is used only for debugging.

But wait, it gets better. Searching the production logs for just one of the ten or so processes that use this code:

$ grep -c "java.lang.Exception: Stack trace" pickme.log

Yes, that is 230,722 stack traces generated for one process in one day. Any surprise at the load averages: 19.33, 16.91, 16.55