Results 1 to 2 of 2
  1. #1
    sushil is offline Member
    Join Date
    Oct 2009
    Rep Power

    Default Problem in knowing the status of windows

    I am doing project in distributing system in java
    i just want to know how to check the status of memory(i.e how much memory is used and how much is empty) in window using java

    so plz help me out

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    The following example shows how much memory that JVM has allocated for your application:

    Java Code:
     Runtime runtime = Runtime.getRuntime();  
     System.out.println("allocated memory: " + runtime.totalMemory() / 1024);
    The following example shows how to discover how much memory is free within the application:
    Java Code:
    Runtime runtime = Runtime.getRuntime();
    System.out.println("free memory: " + runtime.freeMemory() / 1024);
    The freeMemory() method will return the amount of free memory from the allocated memory. Since this value does not include any memory that hasn't yet been allocated by the JVM, you will need to get a complete picture of the free memory that your application would be able to use. To do this, you need to include the amount of memory that hasn't yet bee allocated by the JVM, but could be allocated if necessary.
    Java Code:
        Runtime runtime = Runtime.getRuntime();  
        long maxMemory = runtime.maxMemory();  
        long allocatedMemory = runtime.totalMemory();  
        long freeMemory = runtime.freeMemory();  
        System.out.println("free memory: " + freeMemory / 1024);  
        System.out.println("allocated memory: " + allocatedMemory / 1024);  
        System.out.println("max memory: " + maxMemory /1024);  
        System.out.println("total free memory: " + (freeMemory + (maxMemory - allocatedMemory)) / 1024);

Similar Threads

  1. Need help in knowing how to clear buffer.
    By tedstevens in forum New To Java
    Replies: 1
    Last Post: 08-20-2009, 05:02 AM
  2. Knowing which IP address is active
    By sukatoa in forum Networking
    Replies: 2
    Last Post: 05-05-2009, 04:01 PM
  3. problem with HTTP Status 404
    By orkun in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 02-05-2009, 09:28 PM
  4. Replies: 1
    Last Post: 11-21-2008, 02:13 AM
  5. SWT Status Bar Demo
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts