List of usage examples for java.lang Thread sleep
public static native void sleep(long millis) throws InterruptedException;
From source file:Volatile.java
public static void main(String[] args) { try {//from www . j a v a 2s . co m Volatile vol = new Volatile(); // slight pause to let some time elapse Thread.sleep(100); Thread t = new Thread(vol); t.start(); // slight pause to allow run() to go first Thread.sleep(100); vol.workMethod(); } catch (InterruptedException x) { System.err.println("one of the sleeps was interrupted"); } }
From source file:elasticsearch.SampleElasticsearchApplication.java
public static void main(String[] args) throws Exception { SpringApplication.run(SampleElasticsearchApplication.class, "--debug").close(); Thread.sleep(1000000l); }
From source file:com.fusesource.examples.activemq.SimpleProducer.java
public static void main(String args[]) { Connection connection = null; try {/*from ww w. j a v a 2 s.co m*/ // JNDI lookup of JMS Connection Factory and JMS Destination Context context = new InitialContext(); ConnectionFactory factory = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_NAME); Destination destination = (Destination) context.lookup(DESTINATION_NAME); connection = factory.createConnection(); connection.start(); Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(destination); producer.setTimeToLive(MESSAGE_TIME_TO_LIVE_MILLISECONDS); for (int i = 1; i <= NUM_MESSAGES_TO_BE_SENT; i++) { TextMessage message = session.createTextMessage(i + ". message sent"); LOG.info("Sending to destination: " + destination.toString() + " this text: '" + message.getText()); producer.send(message); Thread.sleep(MESSAGE_DELAY_MILLISECONDS); } // Cleanup producer.close(); session.close(); } catch (Throwable t) { LOG.error(t); } finally { // Cleanup code // In general, you should always close producers, consumers, // sessions, and connections in reverse order of creation. // For this simple example, a JMS connection.close will // clean up all other resources. if (connection != null) { try { connection.close(); } catch (JMSException e) { LOG.error(e); } } } }
From source file:io.smartspaces.service.comm.network.server.internal.netty.NettyUdpBroadcastMasterNetworkCommunicationEndpoint.java
public static void main(String[] args) throws Exception { ExecutorService executorService = Executors.newScheduledThreadPool(1000); NettyUdpBroadcastMasterNetworkCommunicationEndpoint endpoint = new NettyUdpBroadcastMasterNetworkCommunicationEndpoint( 23867, executorService, new StandardExtendedLog("foo", new Jdk14Logger("foo"))); endpoint.startup();// ww w . j a v a 2 s. c om Thread.sleep(1000); for (int i = 0; i < 10; i++) { endpoint.writeBroadcastData("Hello".getBytes()); Thread.sleep(1000); } endpoint.shutdown(); executorService.shutdown(); }
From source file:downloadwolkflow.getWorkFlowList.java
public static void main(String args[]) { CloseableHttpClient httpclient = HttpClients.createDefault(); String[] pageList = getPageList(); System.out.println(pageList.length); for (int i = 1; i < pageList.length; i++) { System.out.println(pageList[i]); System.out.println("---------------------------------------------------------------------------"); HttpGet httpget = new HttpGet(pageList[i]); try {/*from w ww . j a v a 2 s .c om*/ HttpResponse response = httpclient.execute(httpget); String page = EntityUtils.toString(response.getEntity()); Document mainDoc = Jsoup.parse(page); Elements resultList = mainDoc.select("div.resource_list_item"); for (int j = 0; j < resultList.size(); j++) { Element workflowResult = resultList.get(j); Element detailInfo = workflowResult.select("div.main_panel").first().select("p.title.inline") .first().select("a").first(); String detailUrl = "http://www.myexperiment.org" + detailInfo.attributes().get("href") + ".html"; System.out.println(detailUrl); downloadWorkFlow(detailUrl, httpclient); Thread.sleep(1000); } } catch (IOException ex) { Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex); } } try { httpclient.close(); } catch (IOException ex) { Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:webcamcapture.WebCamCapture.java
/** * @param args the command line arguments *///from w w w . j a v a 2s .com public static void main(String[] args) throws IOException { // TODO code application logic here System.loadLibrary(Core.NATIVE_LIBRARY_NAME); httpRequestSend request = new httpRequestSend(); VideoCapture camera = new VideoCapture(0); int x = 0; if (!camera.isOpened()) { System.out.println("Error"); } else { Mat frame = new Mat(); while (true) { if (camera.read(frame)) { System.out.println("Frame Obtained"); System.out.println("Captured Frame Width " + frame.width() + " Height " + frame.height()); Highgui.imwrite("camera" + x + ".jpg", frame); //System.out.println("OK"); // break; request.request("https://fireacc.herokuapp.com/dash", "camera" + x + ".jpg"); x++; } try { //} Thread.sleep(5000); } catch (InterruptedException ex) { System.out.println("stuck"); } } } camera.release(); }
From source file:koper.demo.performance.SendDataEventMsgPerf.java
/** * DataEventMsg ?//from www .j a v a 2s. co m * @param args ?:??? * ?:?????? sleep */ public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("kafka/context-data-message.xml", "kafka/context-data-producer.xml"); Order order = new Order(); order.setId(100); order.setOrderNo("order_no"); order.setCreatedTime("oroder_created_time"); OrderService orderService = (OrderService) context.getBean("orderServiceImpl"); int threadNum = 1; long sleepMs = 1000L; if (args.length >= 1) { threadNum = Integer.parseInt(args[0]); sleepMs = Long.parseLong(args[1]); } final long finalSleepMs = sleepMs; ExecutorService executorService = Executors.newFixedThreadPool(threadNum); for (int i = 0; i < threadNum; ++i) { executorService.execute(() -> { while (true) { orderService.insertOrder(order); try { Thread.sleep(finalSleepMs); } catch (Exception e) { e.printStackTrace(); } } }); } }
From source file:com.apress.prospringintegration.messageflow.workflow.WorkflowMainClient.java
public static void main(String[] ars) throws Exception { ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext( "workflow-gateway.xml"); classPathXmlApplicationContext.start(); ProcessEngine processEngine = classPathXmlApplicationContext.getBean(ProcessEngine.class); deployProcessDefinitions(processEngine, "processes/hello.bpmn20.xml", "processes/gateway.bpmn20.xml"); Map<String, Object> processVariables = new HashMap<String, Object>(); processVariables.put("customerId", 2); ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceByKey("sigateway", processVariables);//w w w . java 2 s . c o m log.debug("the process instance has been started: PI ID # " + pi.getId()); Thread.sleep(1000 * 20); log.debug("waited 20s"); }
From source file:com.honnix.yaacs.admin.lifecycle.Lifecycle.java
/** * @param args//from w w w . jav a2 s . c o m */ public static void main(String[] args) { Lifecycle mainEntrance = null; try { mainEntrance = new Lifecycle(); } catch (ACException e) { LOG.fatal("Error starting YaACs.", e); System.exit(-1); } mainEntrance.start(); LOG.warn("YaACs starts successfully."); while (true) { try { Thread.sleep(PERIOD * 10); } catch (InterruptedException e) { LOG.warn("YaACs stops successfully."); break; } } }
From source file:example.queue.selector.Producer.java
public static void main(String[] args) { String url = BROKER_URL; if (args.length > 0) { url = args[0].trim();/*from w ww .j a v a 2s .co m*/ } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url); Connection connection = null; try { connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("test-queue"); MessageProducer producer = session.createProducer(destination); for (int i = 0; i < NUM_MESSAGES_TO_SEND; i++) { TextMessage message = session.createTextMessage("Message #" + i); System.out.println("Sending message #" + i); if (i % 2 == 0) { System.out.println("Sending to me"); message.setStringProperty("intended", "me"); } else { System.out.println("Sending to you"); message.setStringProperty("intended", "you"); } producer.send(message); Thread.sleep(DELAY); } producer.close(); session.close(); } catch (Exception e) { System.out.println("Caught exception!"); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { System.out.println("Could not close an open connection..."); } } } }