List of usage examples for java.lang Runtime getRuntime
public static Runtime getRuntime()
From source file:com.github.liyp.test.TestMain.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // add a shutdown hook to stop the server Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override// ww w. j a va 2s . c om public void run() { System.out.println("########### shoutdown begin...."); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("########### shoutdown end...."); } })); System.out.println(args.length); Iterator<String> iterator1 = IteratorUtils .arrayIterator(new String[] { "one", "two", "three", "11", "22", "AB" }); Iterator<String> iterator2 = IteratorUtils.arrayIterator(new String[] { "a", "b", "c", "33", "ab", "aB" }); Iterator<String> chainedIter = IteratorUtils.chainedIterator(iterator1, iterator2); System.out.println("=================="); Iterator<String> iter = IteratorUtils.filteredIterator(chainedIter, new Predicate() { @Override public boolean evaluate(Object arg0) { System.out.println("xx:" + arg0.toString()); String str = (String) arg0; return str.matches("([a-z]|[A-Z]){2}"); } }); while (iter.hasNext()) { System.out.println(iter.next()); } System.out.println("==================="); System.out.println("asas".matches("[a-z]{4}")); System.out.println("Y".equals(null)); System.out.println(String.format("%02d", 1000L)); System.out.println(ArrayUtils.toString(splitAndTrim(" 11, 21,12 ,", ","))); System.out.println(new ArrayList<String>().toString()); JSONObject json = new JSONObject("{\"keynull\":null}"); json.put("bool", false); json.put("keya", "as"); json.put("key2", 2212222222222222222L); System.out.println(json); System.out.println(json.get("keynull").equals(null)); String a = String.format("{\"id\":%d,\"method\":\"testCrossSync\"," + "\"circle\":%d},\"isEnd\":true", 1, 1); System.out.println(a.getBytes().length); System.out.println(new String[] { "a", "b" }); System.out.println(new JSONArray("[\"aa\",\"\"]")); String data = String.format("%9d %s", 1, RandomStringUtils.randomAlphanumeric(10)); System.out.println(data.getBytes().length); System.out.println(ArrayUtils.toString("1|2| 3| 333||| 3".split("\\|"))); JSONObject j1 = new JSONObject("{\"a\":\"11111\"}"); JSONObject j2 = new JSONObject(j1.toString()); j2.put("b", "22222"); System.out.println(j1 + " | " + j2); System.out.println("======================"); String regex = "\\d+(\\-\\d+){2} \\d+(:\\d+){2}"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher("2015-12-28 15:46:14 _NC250_MD:motion de\n"); String eventDate = matcher.find() ? matcher.group() : ""; System.out.println(eventDate); }
From source file:com.pinterest.terrapin.controller.TerrapinControllerMain.java
public static void main(String[] args) { PropertiesConfiguration configuration = TerrapinUtil.readPropertiesExitOnFailure( System.getProperties().getProperty("terrapin.config", "controller.properties")); try {// ww w . j a v a2 s.c om LOG.info("Starting controller."); final TerrapinControllerHandler handler = new TerrapinControllerHandler(configuration); handler.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { handler.shutdown(); } }); } catch (Throwable t) { LOG.error("Could not start the controller.", t); } }
From source file:Console.java
public static void main(String[] args) { Runtime rt = Runtime.getRuntime(); Process p = null;/*from w w w.jav a 2s .c om*/ try { /* * Start a new process in which to execute the commands in cmd, using the environment in * env and use pwd as the current working directory. */ p = rt.exec(args);// , env, pwd); new Console(p); System.exit(p.exitValue()); } catch (IOException e) { /* * Couldn't even get the command to start. Most likely it couldn't be found because of a * typo. */ System.out.println("Error starting: " + args[0]); System.out.println(e); } }
From source file:ru.itx.service.ServiceApp.java
public static void main(String[] args) throws Exception { final ServiceApp serviceApp = new ServiceApp(); serviceApp.start();/* ww w . j av a 2 s . c om*/ Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { serviceApp.stop(); } }); Thread.sleep(Long.MAX_VALUE); }
From source file:org.another.logserver.Starter.java
/** * * @param args// w ww.j av a2s. c o m */ public static void main(String[] args) { LOGGER.info("Starting Another Log server ..."); // Initialize components LOGGER.debug("Starting Spring context ..."); final ApplicationContext springContext = new ClassPathXmlApplicationContext("spring.xml"); LOGGER.info("Spring intilization: {}", springContext.getStartupDate()); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { super.run(); LOGGER.debug("Running Shutdown Hook"); Configurator conf = springContext.getBean("configurator", Configurator.class); for (IEndPoint ep : conf.getConfiguredEndPoints().values()) { ep.stop(); } } }); ((AbstractApplicationContext) springContext).registerShutdownHook(); LOGGER.debug("Entering wait loop"); try { while (true) { Thread.sleep(1000 * 60 * 60); } } catch (Exception e) { LOGGER.error("", e); } }
From source file:com.semsaas.utils.anyurl.App.java
public static void main(String[] rawArgs) throws Exception { Properties props = new Properties(); String args[] = processOption(rawArgs, props); String outputFile = props.getProperty("output"); OutputStream os = outputFile == null ? System.out : new FileOutputStream(outputFile); final org.apache.camel.spring.Main main = new org.apache.camel.spring.Main(); main.setApplicationContextUri("classpath:application.xml"); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { main.stop();/*from w w w . jav a 2 s. c o m*/ } catch (Exception e) { } } }); if (args.length > 0) { main.start(); if (main.isStarted()) { CamelContext camelContext = main.getCamelContexts().get(0); String target = rewriteEndpoint(args[0]); boolean producerBased = checkProducerBased(target); InputStream is = null; if (producerBased) { ProducerTemplate producer = camelContext.createProducerTemplate(); is = producer.requestBody(target, null, InputStream.class); } else { ConsumerTemplate consumer = camelContext.createConsumerTemplate(); is = consumer.receiveBody(target, InputStream.class); } IOUtils.copy(is, os); main.stop(); } else { System.err.println("Couldn't trigger jobs, camel wasn't started"); } } else { logger.info("No triggers. Running indefintely"); } }
From source file:com.hortonworks.minicluster.StartMiniHadoopCluster.java
/** * MAKE SURE to start with enough memory -Xmx2048m -XX:MaxPermSize=256 * * Will start a two node Hadoop DFS/YARN cluster * *//*from w ww . j a va2s .co m*/ public static void main(String[] args) throws Exception { System.out.println("=============== Starting YARN/HDFS MINI CLUSTER ==============="); int nodeCount = 2; logger.info("Starting with " + nodeCount + " nodes"); final MiniHadoopCluster yarnCluster = new MiniHadoopCluster("MINI_YARN_CLUSTER", nodeCount); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { yarnCluster.stop(); System.out.println("=============== Stopped YARN/HDFS MINI CLUSTER ==============="); } }); try { yarnCluster.start(); System.out.println("######## MINI CLUSTER started on " + new Date() + ". ########"); System.out.println("\t - YARN log and work directories are available in target/MINI_YARN_CLUSTER"); System.out.println("\t - DFS log and work directories are available in target/MINI_DFS_CLUSTER"); } catch (Exception e) { // won't actually shut down process. Need to see what's going on logger.error("Failed to start mini cluster", e); yarnCluster.close(); } }
From source file:org.openpplsoft.Main.java
/** * Main entry point for the OPS runtime. * @param args command line args to main */// w ww . j a va 2 s . com public static void main(final String[] args) { // The name of the environment to access is expected at args[0] System.setProperty("contextFile", args[0] + ".xml"); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(System.getProperty("contextFile")); // The name of the component to load is expected at args[1] ComponentRuntimeProfile profileToRun = (ComponentRuntimeProfile) ctx.getBean(args[1]); try { Runtime.getRuntime().addShutdownHook(new ENTShutdownHook()); TraceFileVerifier.init(profileToRun); Environment.init((String) ctx.getBean("psEnvironmentName"), profileToRun.getOprid()); Environment.setSystemVar("%Component", new PTString(profileToRun.getComponentName())); Environment.setSystemVar("%Menu", new PTString("SA_LEARNER_SERVICES")); Environment.setSystemVar("%Mode", new PTString(profileToRun.getMode())); Environment.setSystemVar("%Action_UpdateDisplay", new PTString("U")); Environment.setSystemVar("%Action_Add", new PTString("A")); /* * The following system vars can theoretically vary among environments. * However, at the moment, I am running this on identically configured * vanilla PS instances. Therefore, I am not going to externalize these * values for the time being. */ Environment.setSystemVar("%Portal", new PTString("EMPLOYEE")); Environment.setSystemVar("%Node", new PTString("HRMS")); // Since we are verifying against a tracefile, we have to override // the default current date and time with the date and time // on/at which the tracefile was generated. Environment.setSystemVar("%Date", profileToRun.getTraceFileDate()); Environment.setSystemVar("%Time", profileToRun.getTraceFileDateTime()); final Component c = DefnCache.getComponent((String) Environment.getSystemVar("%Component").read(), "GBL"); // Set %Page to the name of the first page in the component. Environment.setSystemVar("%Page", new PTString(c.getPages().get(0).getPNLNAME())); DefnCache.getMenu((String) Environment.getSystemVar("%Menu").read()); ComponentBuffer.init(c); ComponentBuffer.getSearchRecord().fireEvent(PCEvent.SEARCH_INIT, new FireEventSummary()); ComponentBuffer.fillSearchRecord(); ComponentBuffer.assembleBuffers(); ComponentBuffer.expandRecordBuffersWhereNecessary(); ComponentBuffer.addEffDtKeyWhereNecessary(); ComponentBuffer.logPageHierarchyVisual(); ComponentBuffer.printStructure(); ComponentStructureVerifier.verify(profileToRun); ComponentBuffer.materialize(); ComponentBuffer.emitPRM(); ComponentBuffer.firstPassFill(); ComponentBuffer.fireEvent(PCEvent.PRE_BUILD, new FireEventSummary()); ComponentBuffer.runRelatedDisplayProcessing(); ComponentBuffer.runDefaultProcessing(); ComponentBuffer.fireEvent(PCEvent.ROW_INIT, new FireEventSummary()); ComponentBuffer.fireEvent(PCEvent.POST_BUILD, new FireEventSummary()); TraceFileVerifier.logVerificationSummary(false); } catch (final OPSVMachRuntimeException opsvmre) { log.fatal(opsvmre.getMessage(), opsvmre); TraceFileVerifier.logVerificationSummary(true); System.exit(1); } }
From source file:com.eaio.uuid.UUIDPerformance.java
public static void main(String[] args) { Thread[] threads = new Thread[Runtime.getRuntime().availableProcessors()]; for (int i = 0; i < threads.length; ++i) { threads[i] = new Thread(new UUIDRunnable(count / threads.length)); }/*from w ww . j a v a2 s . c o m*/ StopWatch watch = new StopWatch(); watch.start(); for (Thread t : threads) { t.start(); } for (Thread t : threads) { try { t.join(); } catch (InterruptedException e) { // Moo } } watch.stop(); System.out.println(watch.getTime()); }
From source file:trendulo.ingest.Ingest.java
/** * @param args/*from ww w.j a va2 s . co m*/ */ public static void main(String[] args) { final Logger log = Logger.getLogger(Ingest.class); ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); // Start the N-Gram Source final TemporalNGramSource nGramSource = (TemporalNGramSource) context.getBean("nGramSource"); Thread nGramSourceThread = new Thread(nGramSource); nGramSourceThread.start(); // Start the N-Gram Ingester that will take from the source final TemporalNGramIngester nGramIngester = (TemporalNGramIngester) context.getBean("nGramIngester"); Thread nGramIngesterThread = new Thread(nGramIngester); nGramIngesterThread.start(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { log.info("Shutting Down Ingest..."); nGramSource.shutdown(); nGramIngester.shutdown(); } }); }