Tabnine Logo
CountDownLatch.await
Code IndexAdd Tabnine to your IDE (free)

How to use
await
method
in
java.util.concurrent.CountDownLatch

Best Java code snippets using java.util.concurrent.CountDownLatch.await (Showing top 20 results out of 26,595)

Refine searchRefine arrow

  • CountDownLatch.<init>
  • CountDownLatch.countDown
  • Test.<init>
  • Assert.assertTrue
  • Assert.assertEquals
  • PrintStream.println
origin: greenrobot/EventBus

protected void awaitLatch(CountDownLatch latch, long seconds) {
  try {
    assertTrue(latch.await(seconds, TimeUnit.SECONDS));
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
origin: ReactiveX/RxJava

  @Override
  public void run() throws Exception {
    cdl1.countDown();
    cdl2.await(5, TimeUnit.SECONDS);
  }
}).subscribeOn(Schedulers.single()).test();
origin: greenrobot/EventBus

@Test
public void testRacingRegistrations() throws InterruptedException {
  for (int i = 0; i < ITERATIONS; i++) {
    startLatch = new CountDownLatch(THREAD_COUNT);
    registeredLatch = new CountDownLatch(THREAD_COUNT);
    canUnregisterLatch = new CountDownLatch(1);
    unregisteredLatch = new CountDownLatch(THREAD_COUNT);
    
    List<SubscriberThread> threads = startThreads();
    registeredLatch.await();
    eventBus.post("42");
    canUnregisterLatch.countDown();
    for (int t = 0; t < THREAD_COUNT; t++) {
      int eventCount = threads.get(t).eventCount;
      if (eventCount != 1) {
        fail("Failed in iteration " + i + ": thread #" + t + " has event count of " + eventCount);
      }
    }
    // Wait for threads to be done
    unregisteredLatch.await();
  }
}
origin: spring-projects/spring-framework

@Test
public void registerWebSocketHandlerWithSockJS() throws Exception {
  WebSocketSession session = this.webSocketClient.doHandshake(
      new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/sockjs/websocket").get();
  TestHandler serverHandler = this.wac.getBean(TestHandler.class);
  assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
  session.close();
}
origin: ReactiveX/RxJava

@Test
public void testLongTimeAction() throws InterruptedException {
  final CountDownLatch latch = new CountDownLatch(1);
  LongTimeAction action = new LongTimeAction(latch);
  Observable.just(1).buffer(10, TimeUnit.MILLISECONDS, 10)
      .subscribe(action);
  latch.await();
  assertFalse(action.fail);
}
origin: spring-projects/spring-framework

@Test
public void getAndInterceptResponse() throws Exception {
  RequestInterceptor interceptor = new RequestInterceptor();
  template.setInterceptors(Collections.singletonList(interceptor));
  ListenableFuture<ResponseEntity<String>> future = template.getForEntity(baseUrl + "/get", String.class);
  interceptor.latch.await(5, TimeUnit.SECONDS);
  assertNotNull(interceptor.response);
  assertEquals(HttpStatus.OK, interceptor.response.getStatusCode());
  assertNull(interceptor.exception);
  assertEquals(helloWorld, future.get().getBody());
}
origin: ReactiveX/RxJava

@Test
public final void testObserveOn() throws InterruptedException {
  final Scheduler scheduler = getScheduler();
  Flowable<String> f = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten");
  ConcurrentObserverValidator<String> observer = new ConcurrentObserverValidator<String>();
  f.observeOn(scheduler).subscribe(observer);
  if (!observer.completed.await(3000, TimeUnit.MILLISECONDS)) {
    fail("timed out");
  }
  if (observer.error.get() != null) {
    observer.error.get().printStackTrace();
    fail("Error: " + observer.error.get().getMessage());
  }
}
origin: LMAX-Exchange/disruptor

  public static void main(String[] args) throws TimeoutException, InterruptedException
  {
    Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(
      LongEvent.FACTORY, 16, DaemonThreadFactory.INSTANCE
    );

    CountDownLatch shutdownLatch = new CountDownLatch(2);

    disruptor.handleEventsWith(new Handler(shutdownLatch)).then(new Handler(shutdownLatch));
    disruptor.start();

    long next = disruptor.getRingBuffer().next();
    disruptor.getRingBuffer().get(next).set(next);
    disruptor.getRingBuffer().publish(next);

    disruptor.shutdown(10, TimeUnit.SECONDS);

    shutdownLatch.await();

    System.out.println(value);
  }
}
origin: google/guava

 @Override
 public Void call() throws Exception {
  enterLatch.countDown();
  new CountDownLatch(1).await(); // wait forever
  return null;
 }
});
origin: spring-projects/spring-framework

private void stopActiveMqBrokerAndAwait() throws Exception {
  logger.debug("Stopping ActiveMQ broker and will await shutdown");
  if (!this.activeMQBroker.isStarted()) {
    logger.debug("Broker not running");
    return;
  }
  final CountDownLatch latch = new CountDownLatch(1);
  this.activeMQBroker.addShutdownHook(new Runnable() {
    public void run() {
      latch.countDown();
    }
  });
  this.activeMQBroker.stop();
  assertTrue("Broker did not stop", latch.await(5, TimeUnit.SECONDS));
  logger.debug("Broker stopped");
}
origin: spring-projects/spring-framework

private void block() {
  try {
    this.releaseLatch.set(new CountDownLatch(1));
    this.releaseLatch.get().await();
  }
  catch (InterruptedException e) {
    e.printStackTrace();
  }
}
origin: ReactiveX/RxJava

@Test
public void scheduleDirectDelayed() throws Exception {
  Scheduler s = getScheduler();
  final CountDownLatch cdl = new CountDownLatch(1);
  s.scheduleDirect(new Runnable() {
    @Override
    public void run() {
      cdl.countDown();
    }
  }, 50, TimeUnit.MILLISECONDS);
  assertTrue(cdl.await(5, TimeUnit.SECONDS));
}
origin: spring-projects/spring-framework

@Test
public void registerWebSocketHandler() throws Exception {
  WebSocketSession session = this.webSocketClient.doHandshake(
      new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/ws").get();
  TestHandler serverHandler = this.wac.getBean(TestHandler.class);
  assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
  session.close();
}
origin: ReactiveX/RxJava

@Test
public void testLongTimeAction() throws InterruptedException {
  final CountDownLatch latch = new CountDownLatch(1);
  LongTimeAction action = new LongTimeAction(latch);
  Flowable.just(1).buffer(10, TimeUnit.MILLISECONDS, 10)
      .subscribe(action);
  latch.await();
  assertFalse(action.fail);
}
origin: spring-projects/spring-framework

@Test
public void getAndInterceptError() throws Exception {
  RequestInterceptor interceptor = new RequestInterceptor();
  template.setInterceptors(Collections.singletonList(interceptor));
  template.getForEntity(baseUrl + "/status/notfound", String.class);
  interceptor.latch.await(5, TimeUnit.SECONDS);
  assertNotNull(interceptor.response);
  assertEquals(HttpStatus.NOT_FOUND, interceptor.response.getStatusCode());
  assertNull(interceptor.exception);
}
origin: spring-projects/spring-framework

@Test
public void asyncProcessingApplied() throws InterruptedException {
  loadAsync(AsyncEventListener.class);
  String threadName = Thread.currentThread().getName();
  AnotherTestEvent event = new AnotherTestEvent(this, threadName);
  AsyncEventListener listener = this.context.getBean(AsyncEventListener.class);
  this.eventCollector.assertNoEventReceived(listener);
  this.context.publishEvent(event);
  this.countDownLatch.await(2, TimeUnit.SECONDS);
  this.eventCollector.assertEvent(listener, event);
  this.eventCollector.assertTotalEventsCount(1);
}
origin: google/guava

 @Override
 public ListenableFuture<String> call() throws Exception {
  inFunction.countDown();
  try {
   new CountDownLatch(1).await(); // wait for interrupt
  } catch (InterruptedException expected) {
   gotException.countDown();
   throw expected;
  }
  return immediateFuture("a");
 }
};
origin: ReactiveX/RxJava

  @Override
  public Integer call() throws Exception {
    cdl1.countDown();
    cdl2.await(5, TimeUnit.SECONDS);
    return 1;
  }
}).subscribeOn(Schedulers.single()).test();
origin: greenrobot/EventBus

protected void awaitLatch(CountDownLatch latch, long seconds) {
  try {
    assertTrue(latch.await(seconds, TimeUnit.SECONDS));
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
origin: google/guava

public void testAddAfterRun() throws Exception {
 // Run the previous test
 testRunOnPopulatedList();
 // If it passed, then verify an Add will be executed without calling run
 CountDownLatch countDownLatch = new CountDownLatch(1);
 list.add(new MockRunnable(countDownLatch), Executors.newCachedThreadPool());
 assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
}
java.util.concurrentCountDownLatchawait

Javadoc

Causes the current thread to wait until the latch has counted down to zero, unless the thread is Thread#interrupt.

If the current count is zero then this method returns immediately.

If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happen:

  • The count reaches zero due to invocations of the #countDown method; or
  • Some other thread Thread#interruptthe current thread.

If the current thread:

  • has its interrupted status set on entry to this method; or
  • is Thread#interrupt while waiting,
then InterruptedException is thrown and the current thread's interrupted status is cleared.

Popular methods of CountDownLatch

  • countDown
    Decrements the count of the latch, releasing all waiting threads if the count reaches zero.If the cu
  • <init>
    Constructs a CountDownLatch initialized with the given count.
  • getCount
    Returns the current count.This method is typically used for debugging and testing purposes.
  • toString
    Returns a string identifying this latch, as well as its state. The state, in brackets, includes the

Popular in Java

  • Making http requests using okhttp
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • notifyDataSetChanged (ArrayAdapter)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Notification (javax.management)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now