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.linkedin.pinot.broker.broker.BrokerServerBuilderTest.java

public static void main(String[] args) throws Exception {
    PropertiesConfiguration config = new PropertiesConfiguration(
            new File(BrokerServerBuilderTest.class.getClassLoader().getResource("broker.properties").toURI()));
    final BrokerServerBuilder bld = new BrokerServerBuilder(config, null, null, null);
    bld.buildNetwork();/*w w  w  .j  a va  2s. c o  m*/
    bld.buildHTTP();
    bld.start();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                bld.stop();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
        String command = br.readLine();
        if (command.equals("exit")) {
            bld.stop();
        }
    }

}

From source file:mase.MaseManagerTerminal.java

public static void main(String[] args) {
    File r = null, j = null;//  w w  w  . j a  va  2  s.  c om
    if (args.length > 0) {
        r = new File(args[0]);
    }
    if (args.length > 1) {
        j = new File(args[1]);
    }

    final MaseManager manager = new MaseManager();
    final MaseManagerTerminal terminal = new MaseManagerTerminal(manager);
    manager.setStatusListener(terminal);

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            terminal.message("Exiting gracefully");
            manager.cancelAll();
        }
    }));

    manager.startExecution();
    terminal.run(r, j);
}

From source file:de.fionera.javamailer.main.Main.java

/**
 * The Main Class which will be started/*from www.j av  a  2  s  .c o m*/
 *
 * @param args
 */
public static void main(String[] args) {
    ObjectMapper mapper = new ObjectMapper();
    File file = new File("settings.jm");

    try {
        loadSettings(file, mapper);
    } catch (Exception e) {
        e.printStackTrace();
    }

    controllerMain controllerMain = new controllerMain();
    controllerMain.createMainView();

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        saveSettings(file, mapper);
    }));
}

From source file:me.ryandowling.TwitchTools.java

public static void main(String[] args) {
    loadSettings();//from   w  w w  .  j av a 2s. c  o m

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            saveSettings();
        }
    });

    if (args.length == 0) {
        System.err.println("Invalid number of arguments specified!");
        System.exit(1);
    } else if (args.length >= 1 && args.length <= 4) {
        switch (args[0]) {
        case "Followers":
            if (args.length == 4) {
                new Followers(args[1], Integer.parseInt(args[2]), Boolean.parseBoolean(args[3])).run();
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.exit(1);
            }
            break;
        case "MicrophoneStatus":
            if (args.length == 3) {
                final int delay = Integer.parseInt(args[1]);
                final boolean guiDisplay = Boolean.parseBoolean(args[2]);

                new MicrophoneStatus(delay, guiDisplay);
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates] [if the gui should show]!");
                System.err.println("For example: [100] [true]!");
                System.exit(1);
            }
            break;
        case "NowPlayingConverter":
            if (args.length == 2) {
                final int delay = Integer.parseInt(args[1]);
                new NowPlayingConverter(delay).run();
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates]!");
                System.err.println("For example: [100]!");
                System.exit(1);
            }
            break;
        case "MusicCreditsGenerator":
            if (args.length == 2) {
                final String type = args[1];

                if (type.equalsIgnoreCase("html") || type.equalsIgnoreCase("october")
                        || type.equalsIgnoreCase("markdown")) {
                    new MusicCreditsGenerator(type).run();
                } else {
                    System.err.println("Invalid type argument specified!");
                    System.err.println("Arguments are: [type of output to generate (html|markdown|october)]!");
                    System.err.println("For example: [html]!");
                    System.exit(1);
                }
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates]!");
                System.err.println("For example: [100]!");
                System.exit(1);
            }
            break;
        case "SteamGamesGenerator":
            if (args.length == 2) {
                final String type = args[1];

                if (type.equalsIgnoreCase("october")) {
                    new SteamGamesGenerator(type).run();
                } else {
                    System.err.println("Invalid type argument specified!");
                    System.err.println("Arguments are: [type of output to generate (october)]!");
                    System.err.println("For example: [october]!");
                    System.exit(1);
                }
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates]!");
                System.err.println("For example: [100]!");
                System.exit(1);
            }
            break;
        case "FoobarControls":
            if (args.length == 1) {
                new FoobarControls().run();
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("There are no arguments to provide!");
                System.exit(1);
            }
            break;
        default:
            System.err.println("Invalid tool name specified!");
            System.exit(1);
        }
    }
}

From source file:example.rhino.DynamicScopesWithHandlebars.java

public static void main(String[] args) {
    Context cx = Context.enter();
    try {/*from w w w.  java  2  s . c om*/
        String source = handlebars();
        Script script = cx.compileString(source, "handlebars", 1, null);

        System.out.println("Running the script in a single thread");
        runScripts(cx, script, Executors.newSingleThreadExecutor());

        int nThreads = Runtime.getRuntime().availableProcessors();
        System.out.format("Running the script in %d thread\n", nThreads);

        runScripts(cx, script, Executors.newFixedThreadPool(nThreads));

    } catch (IOException e) {
        System.err.println("No handlebars file found");
    } finally {
        Context.exit();
    }
}

From source file:org.sourceopen.hadoop.hbase.replication.server.Consumer.java

public static void main(String args[]) {
    try {//from w w  w .  j a  va  2  s  . c om
        final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(SPRING_PATH);
        // ?
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                try {
                    context.stop();
                    context.close();
                    LOG.info("Consumer server stopped");
                    System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
                            + " Consumer server stoped");
                } catch (Throwable t) {
                    LOG.error("Fail to stop consumer server: ", t);
                }
                synchronized (Consumer.class) {
                    running = false;
                    Consumer.class.notify();
                }

            }
        });
        Configuration conf = HBaseConfiguration.create();
        conf.addResource(ConsumerConstants.COMMON_CONFIG_FILE);
        conf.addResource(ConsumerConstants.CONSUMER_CONFIG_FILE);
        Consumer.start(conf);
        LOG.info("Consumer server started");
        System.out.println(
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " Consumer server started");

    } catch (Throwable t) {
        LOG.error("Fail to start consumer server: ", t);
        System.exit(-1);
    }
    synchronized (Consumer.class) {
        while (running) {
            try {
                Consumer.class.wait();
            } catch (Throwable t) {
                LOG.error("Consumer server got runtime errors: ", t);
            }
        }
    }
}

From source file:com.alibaba.otter.node.deployer.OtterLauncher.java

public static void main(String[] args) throws Throwable {
    // ?dragoon client
    // startDragoon();
    // logger.info("INFO ## the dragoon is start now ......");
    final OtterController controller = OtterContextLocator.getOtterController();
    controller.start();// w ww  .j ava2 s.  c  o m
    try {
        logger.info("INFO ## the otter server is running now ......");
        Runtime.getRuntime().addShutdownHook(new Thread() {

            public void run() {
                try {
                    logger.info("INFO ## stop the otter server");
                    controller.stop();
                } catch (Throwable e) {
                    logger.warn("WARN ##something goes wrong when stopping Otter Server:\n{}",
                            ExceptionUtils.getFullStackTrace(e));
                } finally {
                    logger.info("INFO ## otter server is down.");
                }
            }

        });
    } catch (Throwable e) {
        logger.error("ERROR ## Something goes wrong when starting up the Otter Server:\n{}",
                ExceptionUtils.getFullStackTrace(e));
        System.exit(0);
    }
}

From source file:com.pinterest.terrapin.server.TerrapinServerMain.java

public static void main(String[] args) {
    PropertiesConfiguration configuration = TerrapinUtil.readPropertiesExitOnFailure(
            System.getProperties().getProperty("terrapin.config", "server.properties"));

    try {//from   w w w. j a va 2s.  c  o  m
        final TerrapinServerHandler handler = new TerrapinServerHandler(configuration);
        handler.start();
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                handler.shutdown();
            }
        });
    } catch (Throwable t) {
        LOG.error("Could not start up server.", t);
        System.exit(1);
    }
}

From source file:io.gravitee.gateway.platforms.jetty.bootstrap.Bootstrap.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    t.setName("graviteeio-gateway");

    final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(JettyConfiguration.class);
    ctx.registerShutdownHook();/* w w  w. j  av  a  2  s.c om*/
    ctx.refresh();

    try {
        final Node node = ctx.getBean(Node.class);
        node.start();

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                LoggerFactory.getLogger(Bootstrap.class).info("Shutting-down Gravitee Gateway...");
                node.stop();
                ctx.close();
            }
        });
    } catch (Exception ex) {
        LOGGER.error("Unable to start Gravitee Gateway", ex);
    }
}

From source file:com.sourcethought.simpledaemon.EchoTask.java

public static void main(String[] args) throws Exception {
    // setup command line options
    Options options = new Options();
    options.addOption("h", "help", false, "print this help screen");

    // read command line options
    CommandLineParser parser = new PosixParser();
    try {//www . j  a  va 2s.  c  o  m
        CommandLine cmdline = parser.parse(options, args);

        if (cmdline.hasOption("help") || cmdline.hasOption("h")) {
            System.out.println("SimpleDaemon Version " + Main.version);

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(
                    "java -cp lib/*:target/SimpleDaemon-1.0-SNAPSHOT.jar com.sourcethought.simpledaemon.Main",
                    options);
            return;
        }

        final SimpleDaemon daemon = new SimpleDaemon();
        daemon.start();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                if (daemon.isRunning()) {
                    try {
                        System.out.println("Shutting down daemon...");
                        daemon.stop();
                    } catch (Exception ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }));

    } catch (ParseException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

}