Java 8 CyclicBarrier - 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 CyclicBarrier class.

This code example shows how to use the following methods: await
        v1.add(testStart);
        v1.add(v2);
        v2.add(testStart);
        v2.add(v1);
 
        final CyclicBarrier testEnd = new CyclicBarrier(3);
        final TestThread t1 = new TestThread(v1, testEnd);
        final TestThread t2 = new TestThread(v2, testEnd);
 
        t1.start();
        t2.start();
 
        // Wait for both test threads to have initiated serialization 
        // of the 'testStart' object (and hence of both 'v1' and 'v2') 
        testStart.await();
 
        // Wait for both test threads to successfully finish serialization 
        // of 'v1' and 'v2'. 
        System.out.println("Waiting for Vector serialization to complete ...");
        System.out.println("(This test will hang if serialization deadlocks)");

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
    } 
  } 
 
  public static void main(String[] args)
  { 
    CyclicBarrier barrier = new CyclicBarrier(3);
    new Thread(new DelayedMessagePrinter(barrier, "Enjoy")).start();
    new Thread(new DelayedMessagePrinter(barrier, "Rosetta")).start();
    new Thread(new DelayedMessagePrinter(barrier, "Code")).start();
  } 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
 */ 
@Singleton 
@Startup 
@Remote(HelperSingleton.class) 
public class HelperSingletonImpl implements HelperSingleton { 
    public static CyclicBarrier barrier = new CyclicBarrier(2);
 
    public int await(String where, long timeout, TimeUnit unit) throws BrokenBarrierException, TimeoutException, InterruptedException {
        return barrier.await(timeout, unit);
    } 
     
    public void reset() { 
        barrier.reset();
    } 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
        } 
    } 
 
    /** Test the case where the park times out. */ 
    public void test_parkFor_1() throws Exception { 
        CyclicBarrier barrier = new CyclicBarrier(2);
        Parker parker = new Parker(barrier, false, 500);
        Thread parkerThread = new Thread(parker);
        Thread waiterThread =
            new Thread(new WaitAndUnpark(barrier, 1000, parkerThread));
 
        parkerThread.start();
        waiterThread.start();
        parker.assertDurationIsInRange(500);
        waiterThread.join();
        parkerThread.join();
    } 
 
    /** Test the case where the unpark happens before the timeout. */ 
    public void test_parkFor_2() throws Exception { 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: await
 
      AssertJUnit.assertEquals((Integer) 1, future.get());
   } 
 
   public void testTaskCancellation() throws Exception {
      CyclicBarrier barrier = new CyclicBarrier(2);
      cache(1, cacheName()).getAdvancedCache().getComponentRegistry().registerComponent(barrier, "barrier");
 
      DistributedExecutorService des = createDES(getCache());
      List<Address> cacheMembers = getCache().getAdvancedCache().getRpcManager().getMembers();
      AssertJUnit.assertEquals(caches(cacheName()).size(), cacheMembers.size());
 
      DistributedTaskBuilder<Integer> tb = des.createDistributedTaskBuilder(new LongRunningCallable());
      final Future<Integer> future = des.submit(address(1), tb.build());
      // Will unblock when LongRunningCallable starts running 
      barrier.await(10, TimeUnit.SECONDS);
      future.cancel(true);
      boolean taskCancelled = false;
      try { 
         future.get();

6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 CyclicBarrier Questions & Answers:

See Code Examples for Java 8 CyclicBarrier Methods: