MONITOR MEMORY IN JAVA

Discussion in 'Java' started by memy, Oct 31, 2010.

  1. memy

    memy

    Joined:
    Oct 31, 2010
    Messages:
    1
    HI

    pleas help me i want aprogram

    to monitor memory in java

    to get information

    please help meeeeeeee :bowl:
     
    memy, Oct 31, 2010
    #1
    1. Advertising

  2. memy

    fe.aa

    Joined:
    Nov 2, 2010
    Messages:
    1
    Answer:

    Hope this helps, i came across it a few weeks ago, so i thought i google it and help you out:

    public class MemoryTest {


    public static void main(String [] args) {

    int mb = 1024*1024;

    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    System.out.println("##### Heap utilization statistics [MB] #####");

    //Print used memory
    System.out.println("Used Memory:"
    + (runtime.totalMemory() - runtime.freeMemory()) / mb);

    //Print free memory
    System.out.println("Free Memory:"
    + runtime.freeMemory() / mb);

    //Print total available memory
    System.out.println("Total Memory:" + runtime.totalMemory() / mb);

    //Print Maximum available memory
    System.out.println("Max Memory:" + runtime.maxMemory() / mb);
    }
    }

    Cheers!
     
    fe.aa, Nov 2, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olav Tollefsen

    Out of Memory, how to monitor?

    Olav Tollefsen, Feb 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    415
    Kevin Spencer
    Feb 28, 2005
  2. Ravi Ambros Wallau
    Replies:
    2
    Views:
    3,973
    Ravi Ambros Wallau
    Jan 13, 2006
  3. r.oosterholt@gmail.com

    Monitor Tomcat memory per application

    r.oosterholt@gmail.com, Mar 22, 2007, in forum: Java
    Replies:
    0
    Views:
    616
    r.oosterholt@gmail.com
    Mar 22, 2007
  4. George2
    Replies:
    0
    Views:
    266
    George2
    Jan 13, 2008
  5. ScottZ
    Replies:
    2
    Views:
    389
    Jorgen Grahn
    Nov 2, 2008
Loading...

Share This Page