File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Java Memory Monitoring in Web Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Memory Monitoring in Web Application" Watch "Java Memory Monitoring in Web Application" New topic

Java Memory Monitoring in Web Application

Tarun Trehan
Ranch Hand

Joined: Mar 16, 2012
Posts: 51

Hi All,

Request you to please review the below mentioned suggestion and provide inputs:

Over the years, I have been involved in some projects involving web development in J2ee. JAVA memory usage is an issue that is common amongst all.

Following are some of the questions that come across to a developer regarding the JAVA memory:

  • Memory Usage Statistics.
  • Trending of Memory statistics.
  • Memory Leak.
  • Performance optimization in case memory leaks occur.

  • When it comes to answering the above, the most common suggestion is to enable heap dumps and analyze it using a heap analyzer tool. However, there are times and projects where these options are not approved off and developer is always asked to review code again and again. This is again a frustrating option for someone who has just joined a maintenance project and reading through code is not a feasible option. It has happened to me and I did the following to solve some of my problems and eventually all.

    Instead of analyzing heap dumps, I decided to do the following:

    Add a request filter to my J2EE application.
    Add following log statements in the filter:
  • URL fired.
  • Runtime.getRuntime().freeMemory()
  • Runtime.getRuntime().totalMemory()
  • Runtime.getRuntime().maxMemory()
  • Gather data from daily app usage and build some trending statistics.

  • Not only were we able to decide an optimum memory setting for our server, we were able to detect leaks as well. However, i agree detecting leaks wasn't as simple as it's with other tools considering the debugging effort that's involved.It is not a conventional approach but come sin handy when projects don't want to involve costs and maintain equilibrium at production systems as well.

    Tarun Trehan (
    Ulf Dittmer

    Joined: Mar 22, 2005
    Posts: 42965
    I think those stats will only give you a very cursory picture of what's going on. If that was sufficient for your purposes - great. But if you're looking for some alternative approaches, here are some options you may wish to explore:
  • JavaMonitor lets you monitor distributed servlet containers remotely
  • If you can hook up a JMX client to your JVM, then VisualVM (which comes with the JDK) lets you delve deeply into all kinds of statistics.
  • JaMon API is a combination of servlet filter (for basic monitoring) and API (for more detailed monitoring) for monitoring web apps.
  • Tarun Trehan
    Ranch Hand

    Joined: Mar 16, 2012
    Posts: 51

    Thanks for your inputs.
    I 2nd you on the inputs.

    just posted my review and process at the following link.
    The approach can come handy in typical situations.

    Thanks again for your inputs. Appreciate it !!!
    J. Kevin Robbins

    Joined: Dec 16, 2010
    Posts: 1522

    Psi Probe is another tool worth considering, and NetBeans has an excellent memory profiler tool.

    "The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
    Ulf Dittmer

    Joined: Mar 22, 2005
    Posts: 42965
    I'm not following - you decided not to use any of the tools I recommended? Your write-up seems to be identical to your question here.

    The numbers you get from the System class are really crude; JamonApi can do much better than that, and tallies it up for you as well.

    I second that PSI-Probe is a great tool.
    Tarun Trehan
    Ranch Hand

    Joined: Mar 16, 2012
    Posts: 51


    I work in IT deptt of a financial firm and see a lot of resistance to introduction of new api,etc.
    However, i went through the api and will try to implement in my local practice project that i work on.
    Appreciate your inputs...
    Thanks a lot !!!

    Regarding the post : It was just a information sharing that can be used in some scenarios.
    I agree. Here's the link:
    subject: Java Memory Monitoring in Web Application
    jQuery in Action, 3rd edition