Java 8 CountDownLatch - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 CountDownLatch class.

This code example shows how to use the following methods:countDown
        this.latch = new CountDownLatch(nonMasterNodes);
    } 
 
    @Override 
    public void onResponse(DiscoveryNode node) {
        latch.countDown();
    } 
 
    @Override 
    public void onFailure(DiscoveryNode node, Throwable t) {
        latch.countDown();
    } 
 
    @Override 
    public boolean awaitAllNodes(TimeValue timeout) throws InterruptedException {
        return latch.await(timeout.millis(), TimeUnit.MILLISECONDS);
    } 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:await
 
  public static void main(String[] args) throws InterruptedException {
    final Config config = ConfigFactory.parseString("akka.loglevel=DEBUG");
    final ActorSystem system = ActorSystem.create("EchoServer", config);
    try { 
      final CountDownLatch latch = new CountDownLatch(1);
      final ActorRef watcher = system.actorOf(Props.create(Watcher.class, latch), "watcher");
      final ActorRef nackServer = system.actorOf(Props.create(EchoManager.class, EchoHandler.class), "nack");
      final ActorRef ackServer = system.actorOf(Props.create(EchoManager.class, SimpleEchoHandler.class), "ack");
      watcher.tell(nackServer, ActorRef.noSender());
      watcher.tell(ackServer, ActorRef.noSender());
      latch.await(10, TimeUnit.MINUTES);
    } finally { 
      system.shutdown();
    } 
  } 
 
} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:await
        return shutDownLatch;
    } 
 
    public String getEchoMessage() {
        try { 
            messageLatch.await();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } 
        return echoMessage;
    } 
 
    public void setEchoMessage(final String echoMessage) {
        this.echoMessage = echoMessage;
        messageLatch.countDown();
    } 
 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:await
     */ 
    public void run(final TestEJBRunnable task) throws Exception {
        final Principal principal = ejbContext.getCallerPrincipal();
        logger.debugf("Principal: %s", principal);
        task.setExpectedPrincipal(principal);
        final CountDownLatch latch = new CountDownLatch(1);
        final Runnable r = new Runnable() {
            @Override 
            public void run() { 
                task.run();
                latch.countDown();
            } 
        }; 
        managedThreadFactory.newThread(r).start();
        latch.await();
    } 
 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:countDown
     * Stateless request scope 
     */ 
    @Test 
    public void testRequestScopeActive() throws Exception { 
        AsyncBean bean = lookup(AsyncBean.class);
        final CountDownLatch latch = new CountDownLatch(1);
 
        final Future<Integer> future = bean.testRequestScopeActive(latch);
        latch.countDown();
        int result = future.get();
        Assert.assertEquals(20, result);
    } 
 
    /** 
     * Stateful - void returned 
     */ 
    @Test 
    public void testVoidAsyncStatefulMethod() throws Exception { 
        AsyncStateful bean = lookup(AsyncStateful.class);
        Assert.assertFalse(AsyncStateful.voidMethodCalled);
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:countDown
public class AsyncBeanDescriptor { 
    public static volatile boolean futureMethodCalled = false;
 
    public Future<Boolean> futureMethod(CountDownLatch latch) throws InterruptedException {
        futureMethodCalled = true;
        latch.countDown();
        return new AsyncResult<Boolean>(true);
    } 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:sleep, await, countDown
    */ 
   @Test 
   public void testTimeout() throws Exception 
   { 
      // we use a countdown latch for the 2 threads involved 
      CountDownLatch latch = new CountDownLatch(2);
      // get a write lock 
      Lock writeLock = this.ejbReadWriteLock.writeLock();
      // create a thread which will get hold of a write lock  
      // and do some processing for 5 seconds 
      Thread threadHoldingWriteLock = new Thread(new ThreadHoldingWriteLock(latch, writeLock, 5000));
       
      // get a read lock 
      Lock readLock = this.ejbReadWriteLock.readLock();
       
      // start the write lock thread (which internally will obtain  
      // a write lock and start a 5 second processing) 
      threadHoldingWriteLock.start();
      // wait for few milli sec for the write lock thread to obtain a write lock 
      Thread.sleep(500);

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:countDown
    @Override 
    public void onResponse(T t) {
        try { 
            delegate.onResponse(t);
        } finally { 
            latch.countDown();
        } 
    } 
 
    @Override 
    public void onFailure(Throwable e) {
        try { 
            delegate.onFailure(e);
        } finally { 
            latch.countDown();
        } 
    } 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:await
    hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
  } 
 
  Handler getHandler() {
    try { 
      handlerInitLatch.await();
    } catch (InterruptedException ie) {
      // continue? 
    } 
    return handler;
  } 
 
  @Override 
  public void run() { 
    Looper.prepare();
    handler = new DecodeHandler(activity, hints);
    handlerInitLatch.countDown();
    Looper.loop();
  } 
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    public static final String SETTING_INITIAL_STATE_TIMEOUT = "discovery.initial_state_timeout";
 
    private static class InitialStateListener implements InitialStateDiscoveryListener { 
 
        private final CountDownLatch latch = new CountDownLatch(1);
        private volatile boolean initialStateReceived;
 
        @Override 
        public void initialStateProcessed() { 
            initialStateReceived = true;
            latch.countDown();
        } 
 
        public boolean waitForInitialState(TimeValue timeValue) throws InterruptedException {
            if (timeValue.millis() > 0) {
                latch.await(timeValue.millis(), TimeUnit.MILLISECONDS);
            } 
            return initialStateReceived;
        } 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 CountDownLatch Questions & Answers:

See Code Examples for Java 8 CountDownLatch Methods: