List of usage examples for java.lang Runtime getRuntime
public static Runtime getRuntime()
From source file:Main.java
public static void main(String[] args) { try {//from w w w . ja va 2 s . c o m String[] cmdArray = new String[2]; // the program to open cmdArray[0] = "notepad.exe"; // txt file to open with notepad cmdArray[1] = "test.txt"; File dir = new File("c:/"); String[] envArray = new String[2]; envArray[0] = ""; envArray[1] = ""; Runtime runTime = Runtime.getRuntime(); Process process = runTime.exec(cmdArray, envArray, dir); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(final String[] args) throws Exception { Random RND = new Random(); ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); List<Future<String>> results = new ArrayList<>(10); for (int i = 0; i < 10; i++) { results.add(es.submit(new TimeSliceTask(RND.nextInt(10), TimeUnit.SECONDS))); }// w ww . ja v a 2s . co m es.shutdown(); while (!results.isEmpty()) { Iterator<Future<String>> i = results.iterator(); while (i.hasNext()) { Future<String> f = i.next(); if (f.isDone()) { System.out.println(f.get()); i.remove(); } } } }
From source file:edu.gmu.isa681.server.Main.java
public static void main(String[] args) { log.info("Starting server..."); final Server server = new Server(Constants.SERVER_PORT); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { server.shutdown();//w ww .j a v a 2s. c o m } }); Thread thread = new Thread(server, "ServerThread"); thread.start(); try { thread.join(); } catch (InterruptedException ex) { log.error(ex); } //TODO: implement some CLI to admin the server }
From source file:Main.java
public static void main(String[] args) { List<Integer> list = new ArrayList<>(); long expectedSum = 0; for (int i = 0; i < 10000; i++) { int random = 1 + (int) (Math.random() * ((100 - 1) + 1)); list.add(random);/* ww w . j a v a 2 s .c o m*/ expectedSum += random; } System.out.println("expected sum: " + expectedSum); ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors()); RecursiveSum recursiveSum = new RecursiveSum(list, 0, list.size()); long recSum = forkJoinPool.invoke(recursiveSum); System.out.println("recursive-sum: " + recSum); }
From source file:ExecDemoPartial.java
public static void main(String argv[]) throws IOException { BufferedReader is; // reader for output of process String line;// ww w . j a v a 2 s .c o m final Process p = Runtime.getRuntime().exec(PROGRAM); Thread waiter = new Thread() { public void run() { try { p.waitFor(); } catch (InterruptedException ex) { // OK, just quit this thread. return; } System.out.println("Program terminated!"); done = true; } }; waiter.start(); // getInputStream gives an Input stream connected to // the process p's standard output (and vice versa). We use // that to construct a BufferedReader so we can readLine() it. is = new BufferedReader(new InputStreamReader(p.getInputStream())); while (!done && ((line = is.readLine()) != null)) System.out.println(line); return; }
From source file:ExecDemoLs.java
public static void main(String argv[]) throws IOException { final Process p; // Process tracks one external native process BufferedReader is; // reader for output of process String line;/*from w ww. j av a 2s.c o m*/ p = Runtime.getRuntime().exec(PROGRAM); // Optional: start a thread to wait for the process to terminate. // Don't just wait in main line, but here set a "done" flag and // use that to control the main reading loop below. Thread waiter = new Thread() { public void run() { try { p.waitFor(); } catch (InterruptedException ex) { // OK, just quit. return; } System.out.println("Program terminated!"); done = true; } }; waiter.start(); // getInputStream gives an Input stream connected to // the process p's standard output (and vice versa). We use // that to construct a BufferedReader so we can readLine() it. is = new BufferedReader(new InputStreamReader(p.getInputStream())); while (!done && ((line = is.readLine()) != null)) System.out.println(line); return; }
From source file:de.daibutsu.main.MainStart.java
public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new ExitHandler()); SwingUtilities.invokeLater(new MainStart()); }
From source file:com.delphix.appliance.host.example.server.ExampleServerLauncher.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_LOCATION); try {/* w w w .jav a2s . c o m*/ final ExampleServer server = (ExampleServer) context.getBean("server"); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { server.fini(); } }); } finally { context.close(); } }
From source file:gridool.GridMain.java
public static void main(String[] args) { final Thread parent = Thread.currentThread(); final GridServer grid = new GridServer(); try {/*from www.ja va 2 s . c om*/ grid.start(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { parent.interrupt(); } }); } catch (InternalException ie) { shutdown(grid, ie); } catch (Throwable e) { shutdown(grid, e); } try { Thread.currentThread().join(); } catch (InterruptedException e) { ; } finally { try { grid.shutdown(true); } catch (RemoteException re) { ; } } }
From source file:org.openmrs.ModuleStory.java
public static void main(String args[]) throws IOException, InterruptedException { if (!skipDatabaseSetupPage()) { String databaseUserName = System.getProperty("database_user_name", "root"); String databaseRootPassword = System.getProperty("database_root_password", "password"); Runtime runtime = Runtime.getRuntime(); runtime.exec("curl http://localhost:8080/openmrs/auto_run_openmrs?local=en&remember=true" + "&database_user_name=" + databaseUserName + "&database_root_password=" + databaseRootPassword); log.debug("Waiting 10 minutes for OpenMRS installation to complete!!"); Thread.sleep(1000 * 60 * 10); //Waiting 10 minutes for installation to complete }/*from w w w. j av a 2s . c o m*/ }