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:com.adito.server.Main.java

/**
 * Entry point//from   ww w .j  a  v a 2s. c  o m
 * 
 * @param args
 * @throws Throwable
 */
public static void main(String[] args) throws Throwable {

    // This is a hack to allow the Install4J installer to get the java
    // runtime that will be used
    if (args.length > 0 && args[0].equals("--jvmdir")) {
        System.out.println(SystemProperties.get("java.home"));
        System.exit(0);
    }
    useWrapper = System.getProperty("wrapper.key") != null;
    final Main main = new Main();
    ContextHolder.setContext(main);

    if (useWrapper) {
        WrapperManager.start(main, args);
    } else {
        Integer returnCode = main.start(args);
        if (returnCode != null) {
            if (main.gui) {
                if (main.startupException == null) {
                    main.startupException = new Exception("An exit code of " + returnCode + " was returned.");
                }
                try {
                    if (SystemProperties.get("os.name").toLowerCase().startsWith("windows")) {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    }
                } catch (Exception e) {
                }
                String mesg = main.startupException.getMessage() == null ? "No message supplied."
                        : main.startupException.getMessage();
                StringBuffer buf = new StringBuffer();
                int l = 0;
                char ch = ' ';
                for (int i = 0; i < mesg.length(); i++) {
                    ch = mesg.charAt(i);
                    if (l > 50 && ch == ' ') {
                        buf.append("\n");
                        l = 0;
                    } else {
                        if (ch == '\n') {
                            l = 0;
                        } else {
                            l++;
                        }
                        buf.append(ch);
                    }
                }
                mesg = buf.toString();
                final String fMesg = mesg;
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(null, fMesg, "Startup Error", JOptionPane.ERROR_MESSAGE);
                    }
                });
            }
            System.exit(returnCode.intValue());
        } else {
            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    if (!main.shuttingDown) {
                        main.stop(0);
                    }
                }
            });
        }
    }
}

From source file:Main.java

public static long getMaxMemory() {
    return Runtime.getRuntime().maxMemory();
}

From source file:Main.java

/**
 * Determines proper size for a thread pool based upon the number of cores
 * and the specified blocking coefficient.
 * <p>//from  w  w  w . j a  v a  2  s  .  com
 * Based upon code from "Programming Concurrency on the JVM", page 23.
 * 
 * @param blockingCoefficient
 * @return poolSize
 * @see #determineThreadPoolSize()
 */
public static int determineThreadPoolSize(final double blockingCoefficient) {
    final int numberOfCores = Runtime.getRuntime().availableProcessors();
    final int poolSize = (int) (numberOfCores / (1 - blockingCoefficient));
    return poolSize;
}

From source file:Main.java

public static String dumpFile_prev(String filename) {
    String line_prev = "";
    try {//w w  w  .j  a v a2s.  co m
        Process ifc_prev = Runtime.getRuntime().exec("cat " + filename);
        BufferedReader bis_prev = new BufferedReader(new InputStreamReader(ifc_prev.getInputStream()));
        line_prev = bis_prev.readLine();
        ifc_prev.destroy();

    } catch (java.io.IOException e) {
        return new String("");
    }

    return line_prev;
}

From source file:Main.java

public static void clearLogs() {
    try {/*from  w ww.j  av  a 2  s. c o  m*/
        Runtime.getRuntime().exec(new String[] { "logcat", "-c" });
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String dumpFile_prev2(String filename) {
    String line_prev2 = "";
    try {/*from  w ww. j av  a  2 s  .c  o  m*/
        Process ifc_prev2 = Runtime.getRuntime().exec("cat " + filename);
        BufferedReader bis_prev2 = new BufferedReader(new InputStreamReader(ifc_prev2.getInputStream()));
        line_prev2 = bis_prev2.readLine();
        ifc_prev2.destroy();

    } catch (java.io.IOException e) {
        return new String("");
    }

    return line_prev2;
}

From source file:Main.java

public static String dumpFile_spica(String filename) {
    String line_spica = "";
    try {/*from w  w w.ja  v  a 2  s.  com*/
        Process ifc_spica = Runtime.getRuntime().exec("cat " + filename);
        BufferedReader bis_spica = new BufferedReader(new InputStreamReader(ifc_spica.getInputStream()));
        line_spica = bis_spica.readLine();
        ifc_spica.destroy();

    } catch (java.io.IOException e) {
        return new String("");
    }

    return line_spica;
}

From source file:Main.java

public static String getMotherboardSN() {
    String result = "";
    try {/*from   ww  w.  j a va 2  s .c  om*/
        File file = File.createTempFile("realhowto", ".vbs");
        file.deleteOnExit();
        FileWriter fw = new java.io.FileWriter(file);

        String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
                + "Set colItems = objWMIService.ExecQuery _ \n" + "   (\"Select * from Win32_BaseBoard\") \n"
                + "For Each objItem in colItems \n" + "    Wscript.Echo objItem.SerialNumber \n"
                + "    exit for  ' do the first cpu only! \n" + "Next \n";

        fw.write(vbs);
        fw.close();
        Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = input.readLine()) != null) {
            result += line;
        }
        input.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result.trim();
}

From source file:Main.java

public static String dumpFile_spica2(String filename) {
    String line_spica2 = "";
    try {//from  w  w w .  jav  a2s.  co m
        Process ifc_spica2 = Runtime.getRuntime().exec("cat " + filename);
        BufferedReader bis_spica2 = new BufferedReader(new InputStreamReader(ifc_spica2.getInputStream()));
        line_spica2 = bis_spica2.readLine();
        ifc_spica2.destroy();

    } catch (java.io.IOException e) {
        return new String("");
    }

    return line_spica2;
}

From source file:com.qwazr.utils.RuntimeUtils.java

public static long getMemoryUsage() {
    Runtime runtime = Runtime.getRuntime();
    return runtime.totalMemory() - runtime.freeMemory();
}