Example usage for java.lang Runtime getRuntime

List of usage examples for java.lang Runtime getRuntime

Introduction

In this page you can find the example usage for java.lang Runtime getRuntime.

Prototype

public static Runtime getRuntime() 

Source Link

Document

Returns the runtime object associated with the current Java application.

Usage

From source file:Main.java

public static void main(String[] args) {

    Runtime runTime = Runtime.getRuntime();
    runTime.runFinalization();//  w w  w .  j a  va2  s  .  c o m
    System.out.println("Done.");

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            System.out.println("Do shutdown work ...");
        }/*from   ww  w  .  jav  a2 s.com*/
    });

}

From source file:Main.java

public static void main(String[] args) {

    Runtime runTime = Runtime.getRuntime();

    // print the number of free bytes
    System.out.println(runTime.freeMemory());

}

From source file:ExecDemoFini.java

public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    Process p = null;//from w ww.  j  av a  2 s  . c  o m

    try {
        p = r.exec("notepad");
        p.waitFor();
    } catch (Exception e) {
        System.out.println("Error executing notepad.");
    }
    System.out.println("Notepad returned " + p.exitValue());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    long heapSize = Runtime.getRuntime().totalMemory();

    long heapMaxSize = Runtime.getRuntime().maxMemory();

    long heapFreeSize = Runtime.getRuntime().freeMemory();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Runtime runTime = Runtime.getRuntime();

    long heapSize = runTime.totalMemory();

    long heapMaxSize = runTime.maxMemory();

    long heapFreeSize = runTime.freeMemory();

}

From source file:Main.java

public static void main(String[] args) {

    // halt this process
    Runtime runTime = Runtime.getRuntime();
    runTime.halt(0);
}

From source file:MemoryDemo.java

public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    long mem1, mem2;
    Integer someints[] = new Integer[1000];

    System.out.println("Total memory is: " + r.totalMemory());

    mem1 = r.freeMemory();/*from w  w w . j  a va  2 s  .co  m*/
    System.out.println("Initial free memory: " + mem1);
    r.gc();
    mem1 = r.freeMemory();
    System.out.println("Free memory after garbage collection: " + mem1);

    for (int i = 0; i < 1000; i++)
        someints[i] = new Integer(i); // allocate integers

    mem2 = r.freeMemory();
    System.out.println("Free memory after allocation: " + mem2);
    System.out.println("Memory used by allocation: " + (mem1 - mem2));

    for (int i = 0; i < 1000; i++)
        someints[i] = null;

    r.gc(); // request garbage collection

    mem2 = r.freeMemory();
    System.out.println("Free memory after collecting" + " discarded Integers: " + mem2);

}

From source file:Main.java

public static void main(String[] args) {

    // print the total memory
    Runtime runTime = Runtime.getRuntime();

    System.out.println(runTime.totalMemory());

}

From source file:Main.java

public static void main(String[] args) {

    // cause the program to exit
    Runtime runTime = Runtime.getRuntime();
    runTime.exit(0);

}