MONITOR MEMORY IN JAVA

Joined
Oct 31, 2010
Messages
1
Reaction score
0
HI

pleas help me i want aprogram

to monitor memory in java

to get information

please help meeeeeeee :bowl:
 
Joined
Nov 2, 2010
Messages
1
Reaction score
0
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top