List of usage examples for java.lang Thread sleep
public static native void sleep(long millis) throws InterruptedException;
From source file:com.github.tsouza.promises.example.BlockingIOPromise.java
public static void main(String[] args) throws Exception { Promises.defer((Resolver<String> resolver) -> { URL url = new URL("http://api.ipify.org"); try (InputStream stream = url.openStream()) { resolver.resolve(IOUtils.toString(stream)); }/*w ww .jav a 2 s .com*/ }, ThreadProfile.IO).done(System.out::println); Thread.sleep(5000); }
From source file:EarlyNotify.java
public static void main(String[] args) { final EarlyNotify enf = new EarlyNotify(); Runnable runA = new Runnable() { public void run() { try { String item = enf.removeItem(); print("returned: '" + item + "'"); } catch (InterruptedException ix) { print("interrupted!"); } catch (Exception x) { print("threw an Exception!!!\n" + x); }//from w ww.ja va 2 s.c o m } }; Runnable runB = new Runnable() { public void run() { enf.addItem("Hello!"); } }; try { Thread threadA1 = new Thread(runA, "A"); threadA1.start(); Thread.sleep(500); Thread threadA2 = new Thread(runA, "B"); threadA2.start(); Thread.sleep(500); Thread threadB = new Thread(runB, "C"); threadB.start(); Thread.sleep(1000); threadA1.interrupt(); threadA2.interrupt(); } catch (InterruptedException x) { } }
From source file:fr.irit.smac.libs.tooling.plot.example.local.LocalChart.java
public static void main(String[] args) { // First, we inform the server that the chart "Layer" must be of type // PLOT/* ww w .j av a 2 s. c om*/ AgentPlot.getServer().configChart("Layer", EChartType.PLOT); // Add plots to the chart "Layer" for serie #0 AgentPlot.getChart("Layer").add(1, 2); AgentPlot.getChart("Layer").add(2, 2.5); AgentPlot.getChart("Layer").add(2, 3); // Add plots to the chart "Layer" for serie "My serie" AgentPlot.getChart("Layer").add("My serie", 21, 2); AgentPlot.getChart("Layer").add("My serie", 12, 2.5); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Add plots to the chart "My Chart" which will be created during this // call AgentPlot.getChart("My chart").add(2, 3); AgentPlot.getChart("My chart").add(3, 3); AgentPlot.getChart("My chart").add(3, 4); // Access the JFreeChart object (only from the server side) JFreeChart chart = ((AgentPlotChart) (AgentPlot.getChart("My chart"))).getJFreeChart(); // Change its title chart.getTitle().setText("New title"); // Close chart // AgentPlot.getChart("My chart").close(); // AgentPlot.getChart("Layer").close(); }
From source file:ru.itx.service.ServiceApp.java
public static void main(String[] args) throws Exception { final ServiceApp serviceApp = new ServiceApp(); serviceApp.start();//from ww w . jav a 2 s .co m Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { serviceApp.stop(); } }); Thread.sleep(Long.MAX_VALUE); }
From source file:com.roncoo.pay.app.settlement.SettTask.java
public static void main(String[] args) { try {//from w ww . j av a 2s . co m @SuppressWarnings("resource") final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring-context.xml" }); context.start(); LOG.debug(""); SettScheduled settScheduled = (SettScheduled) context.getBean("settScheduled"); LOG.debug("(??)"); settScheduled.launchDailySettCollect(); LOG.debug("(??)?"); Thread.sleep(MILLIS); LOG.debug("()"); settScheduled.launchAutoSett(); LOG.debug("()?"); context.stop(); } catch (Exception e) { LOG.error("SettTask execute error:", e); } finally { System.exit(0); LOG.debug("SettTask Complete"); } }
From source file:com.apress.prospringintegration.springbatch.integration.Main.java
public static void main(String[] args) throws Throwable { ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( "integration.xml"); classPathXmlApplicationContext.start(); JobLauncher jobLauncher = (JobLauncher) classPathXmlApplicationContext.getBean("jobLauncher"); Job job = (Job) classPathXmlApplicationContext.getBean("importData"); JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); jobParametersBuilder.addDate("date", new Date()); jobParametersBuilder.addString("input.file", "registrations"); JobParameters jobParameters = jobParametersBuilder.toJobParameters(); JobExecution jobExecution = jobLauncher.run(job, jobParameters); BatchStatus batchStatus = jobExecution.getStatus(); while (batchStatus.isRunning()) { System.out.println("Still running..."); Thread.sleep(1000); }/*from www .j a v a2s . c om*/ System.out.println("Exit status: " + jobExecution.getExitStatus().getExitCode()); JobInstance jobInstance = jobExecution.getJobInstance(); System.out.println("job instance Id: " + jobInstance.getId()); }
From source file:com.dianping.dpsf.other.echo.EchoClient.java
/** * @param args// ww w. j a v a 2 s. c o m * @throws Exception */ public static void main(String[] args) throws Exception { PigeonClientMock.setServiceAddress("127.0.0.1:20001,127.0.0.1:20002"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-client.xml"); IEcho s = (IEcho) ctx.getBean("echo"); // System.out.println(s.echo("aa")); // Thread.sleep(3000); // System.out.println(s.echo("aa")); // System.out.println("firing"); Random rnd = new Random(System.currentTimeMillis()); List<String[]> hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); int i = 0; while (i < 100) { try { System.out.println(s.echo("aa")); } catch (Exception e) { System.out.println("EEEEEEEEEEEEEEEEEEEEEEE"); } Thread.sleep(2000); if (i == 1) { System.out.println("+++++++++++++++++++adding 20002++++++++++++++++"); hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); hostList.add(new String[] { "127.0.0.1", "20002", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); } if (i == 5) { System.out.println("+++++++++++++++++++adding 20003++++++++++++++++"); hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001", "1" }); hostList.add(new String[] { "192.168.32.111", "20003", "1" }); PigeonClientMock.getSc().onServiceHostChange("http://service.dianping.com/echoService", hostList); } if (i == 10) { System.out.println("--------------------change wt------------"); PigeonClientMock.getSc().onHostWeightChange("127.0.0.1", 2); } i++; } }
From source file:com.xoriant.akka.mongodb.bulkimport.main.Application.java
public static void main(String[] args) throws Exception { ApplicationContext ctx = new GenericXmlApplicationContext("springconfig.xml"); final ActorSystem _system = ActorSystem.create("FileImportApp"); final ActorRef mongoInsertionActor = _system.actorOf(Props.create(MongoInsertionActor.class, ctx) .withRouter(new RoundRobinPool(INSERTION_ACTOR_POOL_SIZE))); final ActorRef fileReaderActor = _system .actorOf(Props.create(FileReaderActor.class, mongoInsertionActor, BATCH_SIZE)); String path = Thread.currentThread().getContextClassLoader().getResource("NameList.csv").getFile(); fileReaderActor.tell(path, ActorRef.noSender()); Thread.sleep(5000); _system.shutdown();/*from w w w . j ava 2 s . c o m*/ }
From source file:InterruptibleSyncBlock.java
public static void main(String[] args) { try {/*from ww w .j a v a 2s. com*/ InterruptibleSyncBlock sb = new InterruptibleSyncBlock(); Thread t1 = launch(sb, "T1"); Thread.sleep(500); Thread t2 = launch(sb, "T2"); Thread t3 = launch(sb, "T3"); Thread.sleep(1000); print("about to interrupt T2"); t2.interrupt(); print("just interrupted T2"); } catch (InterruptedException x) { x.printStackTrace(); } }
From source file:hu.vanio.jms.spring3.ibmmq.Start.java
public static void main(String[] args) throws IOException, InterruptedException { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:/application.xml"); // sending messages JmsQueueSender jqs = ctx.getBean(JmsQueueSender.class); String message = "Hello queue world!" + " National chars (see CCSID): \"--\"''<>&@# AE: "; // send five message and sleep half second for (int i = 1; i <= 5; i++) { Thread.sleep(500); jqs.simpleSend(i + ". " + message); }//from www .jav a2s . c om // quit after 1 second Thread.sleep(1000); ctx.destroy(); }