public class MemoryDemo {
public static void main(String[] args) {
/* Total number of processors or cores available to the JVM */
System.out.println("Available processors (cores): " +
Runtime.getRuntime().availableProcessors());
/* Total amount of free memory available to the JVM */
System.out.println("Free memory (bytes): " +
Runtime.getRuntime().freeMemory());
/* This will return Long.MAX_VALUE if there is no preset limit */
long maxMemory = Runtime.getRuntime().maxMemory();
/* Maximum amount of memory the JVM will attempt to use */
System.out.println("Maximum memory (bytes): " +
(maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
/* Total memory currently in use by the JVM */
System.out.println("Total memory (bytes): " +
Runtime.getRuntime().totalMemory());
}
}
java -Xmx8129m -Xms8g -XX:+UseG1GC MemoryDemo
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size
~ java -Xmx8g -Xms8g -XX:+UseG1GC MemoryDemo
Available processors (cores): 12
Free memory (bytes): 8585738240
Maximum memory (bytes): 8589934592
Total memory (bytes): 8589934592