Skip to content

Instantly share code, notes, and snippets.

@mrowe
Created May 17, 2020 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrowe/48a27df964dfb53bede908d60ec6fabd to your computer and use it in GitHub Desktop.
Save mrowe/48a27df964dfb53bede908d60ec6fabd to your computer and use it in GitHub Desktop.
Debugging weird prod problem

We were in the final push towards a major release of a large public-facing J2EE application when I was assigned The Defect. The application, which had been working quite well in functional test environments (all things considered), suddenly stopped when deployed to SIT. Well, it started up ok, but if you tried to log in, you were faced with a long wait. Very long.

It was exactly the same code that had been working in other environments, but the difference in SIT, of course, was that debug logging was turned off.

After a day of changing logging levels, bouncing WebSphere servers and tracing debug logging code, I stumbled across this gem:

    Iterator i = formBean.getKeys();
    while (i.hasNext()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Form attribute: " + i.next());
        }
    }

Adding that call to isDebugEnabled() certainly improved the performance of the code when debug was disabled--it now called i.hasNext() just as fast as the CPU could manage. It's just a shame hasNext() never got to return anything but true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment