The following code sample shows how to output information about free memory, total memory, and JVM properties:
import java.util.*;
import java.io.*;
public class printMemAndProps {
public static void main (String[] args) {
System.out.println(new Date()); // print system date
// get runtime info and print Free/Total memory
Runtime rte = Runtime.getRuntime();
long freeMem = rte.freeMemory();
long totalMem = rte.totalMemory();
System.out.println("Free Memory: " + freeMem);
System.out.println("Total Memory: " + totalMem + "\n");
java.util.Properties p = null;
try {
p = System.getProperties();
}
catch(Exception e) {
e.printStackTrace();
return;
}
p.list(System.out); // print all JVM propererties
}
}
| Copyright © 2005. Sybase Inc. All rights reserved. |
|
|