List of usage examples for java.util.concurrent CountDownLatch CountDownLatch
public CountDownLatch(int count)
From source file:com.dianping.dpsf.other.echo.EchoServer3.java
/** * @param args// w w w . jav a2 s. c o m * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { Thread.currentThread().setName("=============EchoSerer3============"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server3.xml"); if (args.length == 0) { //stand alone start CountDownLatch latch = new CountDownLatch(1); latch.await(); } }
From source file:com.dianping.dpsf.other.echo.EchoServer4.java
/** * @param args//from w w w . j av a 2 s .c om * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { Thread.currentThread().setName("=============EchoSerer4============"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server4.xml"); if (args.length == 0) { //stand alone start CountDownLatch latch = new CountDownLatch(1); latch.await(); } }
From source file:se.sawano.eureka.legacyregistrar.boot.ExampleBootApplication.java
public static void main(String[] args) throws InterruptedException { SpringApplication.run(ExampleBootApplication.class, args); new CountDownLatch(1).await(); }
From source file:LatchHelperService.java
public static void main(String[] args) { // Create a countdown latch with 2 as its counter CountDownLatch latch = new CountDownLatch(2); LatchMainService ms = new LatchMainService(latch); ms.start();/*from w w w . j a va 2 s.c o m*/ for (int i = 1; i <= 2; i++) { LatchHelperService lhs = new LatchHelperService(i, latch); lhs.start(); } }
From source file:org.apache.geode.geospatial.grid.SpringBootGeodeServer.java
public static void main(String[] args) throws InterruptedException { SpringApplication.run(SpringBootGeodeServer.class); CountDownLatch countDownLatch = new CountDownLatch(1); countDownLatch.await();/*from ww w . j a v a 2 s. co m*/ }
From source file:ch.rasc.wampspring.demo.client.CallClient.java
public static void main(String[] args) throws InterruptedException { WebSocketClient webSocketClient = new StandardWebSocketClient(); JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper()); CountDownLatch latch = new CountDownLatch(1_000_000); TestTextWebSocketHandler handler = new TestTextWebSocketHandler(jsonFactory, latch); Long[] start = new Long[1]; ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler, "ws://localhost:8080/wamp"); future.addCallback(wss -> {/* w w w . j a va 2 s .c o m*/ start[0] = System.currentTimeMillis(); for (int i = 0; i < 1_000_000; i++) { CallMessage callMessage = new CallMessage(UUID.randomUUID().toString(), "testService.sum", i, i + 1); try { wss.sendMessage(new TextMessage(callMessage.toJson(jsonFactory))); } catch (Exception e) { System.out.println("ERROR SENDING CALLMESSAGE" + e); latch.countDown(); } } }, t -> { System.out.println("DO HANDSHAKE ERROR: " + t); System.exit(1); }); if (!latch.await(3, TimeUnit.MINUTES)) { System.out.println("SOMETHING WENT WRONG"); } System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds"); System.out.println("SUCCESS: " + handler.getSuccess()); System.out.println("ERROR : " + handler.getError()); }
From source file:ch.rasc.wampspring.demo.client.Publisher.java
public static void main(String[] args) throws InterruptedException { WebSocketClient webSocketClient = new StandardWebSocketClient(); final JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper()); final CountDownLatch welcomeLatch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1_000_000); TextWebSocketHandler handler = new TextWebSocketHandler() { @Override//from ww w.ja va 2s . c om protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { WampMessage wampMessage = WampMessage.fromJson(jsonFactory, message.getPayload()); if (wampMessage instanceof WelcomeMessage) { latch.countDown(); } } }; Long[] start = new Long[1]; ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler, "ws://localhost:8080/wamp"); future.addCallback(wss -> { // Waiting for WELCOME message try { welcomeLatch.await(5, TimeUnit.SECONDS); start[0] = System.currentTimeMillis(); for (int i = 0; i < 1_000_000; i++) { PublishMessage publishMessage = new PublishMessage("/test/myqueue", i); try { wss.sendMessage(new TextMessage(publishMessage.toJson(jsonFactory))); } catch (Exception e) { System.out.println("ERROR SENDING PUBLISH_MESSAGE" + e); } latch.countDown(); } } catch (Exception e1) { System.out.println("SENDING PUBLISH MESSAGES: " + e1); } }, t -> { System.out.println("DO HANDSHAKE ERROR: " + t); System.exit(1); }); if (!latch.await(3, TimeUnit.MINUTES)) { System.out.println("SOMETHING WENT WRONG"); } System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds"); }
From source file:com.github.liyp.dubbo.consumer.Consumer.java
public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "com/github/liyp/dubbo/consumer/consumer.xml" }); context.start();/*from w w w .j av a2s. co m*/ NotifyImpl notify = (NotifyImpl) context.getBean("callback"); HelloService service = (HelloService) context.getBean("service"); System.out.println("dubbo consumer running..."); int i = 0; while (true) { String res = service.sayHello(new HelloBean(i, "lee")); // service.sayHello(i); System.out.println(ai.incrementAndGet()); if (ai.get() >= limit) { locked = true; cdl = new CountDownLatch(limit); cdl.await(); locked = false; } // Thread.sleep(1000); i++; } }
From source file:example.topic.Subscriber.java
public static void main(String[] args) { String url = BROKER_URL; if (args.length > 0) { url = args[0].trim();//from w w w . j av a 2 s . c o m } System.out .println("\nWaiting to receive messages... Either waiting for END message or press Ctrl+C to exit"); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url); Connection connection = null; final CountDownLatch latch = new CountDownLatch(1); try { connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic("test-topic"); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new Subscriber(latch)); latch.await(); consumer.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..."); } } } }
From source file:example.topic.durable.Subscriber.java
public static void main(String[] args) { String url = BROKER_URL; if (args.length > 0) { url = args[0].trim();/*from w ww . j a va2s. c o m*/ } System.out .println("\nWaiting to receive messages... Either waiting for END message or press Ctrl+C to exit"); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url); Connection connection = null; final CountDownLatch latch = new CountDownLatch(1); try { connection = connectionFactory.createConnection(); String clientId = System.getProperty("clientId"); connection.setClientID(clientId); connection.start(); Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); Topic destination = session.createTopic("test-topic"); MessageConsumer consumer = session.createDurableSubscriber(destination, clientId); consumer.setMessageListener(new Subscriber(latch)); latch.await(); consumer.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..."); } } } }