Printing Runtime Basic Information

This section provides a tutorial example on how to access the Runtime instance of a running JVM and print some basic information.

To see how to access the Runtime instance of a running JVM and get some basic information, I wrote this simple Runtime test program, RuntimeMemory.java:

/**
 * RuntimeMemory.java
 * Copyright (c) 2010, HerongYang.com, All Rights Reserved.
 */
class RuntimeMemory {
   public static void main(String[] a) {
      java.io.PrintStream out = System.out;

      // getting the Runtime instance of the JVM
      Runtime rt = Runtime.getRuntime();

      // obtaining basic information
      out.println("# of processors: " + rt.availableProcessors());
      out.println(" Maximum memory: " + rt.maxMemory());
      out.println("   Total memory: " + rt.totalMemory());
      out.println("    Free memory: " + rt.freeMemory());
   }
}

When executed on my Windows 7 system with JDK 1.7.0 in 2010 I got this result:

C:\herong\jvm>java RuntimeMemory
# of processors: 4
 Maximum memory: 259522560
   Total memory: 16252928
    Free memory: 15964856

The test result tells me that:

As a comparison, here is the result of the same program executed on my Windows XP system with JDK 1.6.0 in 2010:

C:\herong\jvm>java RuntimeMemory
# of processors: 2
 Maximum memory: 66650112
   Total memory: 5177344
    Free memory: 4993136

Of course, I can lower the maximum memory by using the -Xmx command option:

C:\herong\jvm>java -Xmx8m RuntimeMemory
# of processors: 4
 Maximum memory: 8126464
   Total memory: 8126464
    Free memory: 7842232

Last update: 2014.

Table of Contents

 About This Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

java.lang.Runtime Class - The JVM Instance

 What Is Runtime?

Printing Runtime Basic Information

 Running the Garbage Collector Explicitly

 Shutting Down or Terminating the JVM Instance

 Executing System Commands

 Loading Native Libraries

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 Sun's JVM - Java HotSpot VM

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Runtime Data Areas

 Memory Management and Garbage Collectors

 Garbage Collection Tests

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 Outdated Tutorials

 References

 PDF Printing Version