Examples of CountDownLatch


Examples of java.util.concurrent.CountDownLatch

      startCacheServer();
   }

   private static void startCacheServer()
   {
      final CountDownLatch startedSignal = new CountDownLatch(1);

      Thread t = new Thread()
      {
         public void run()
         {
            try
            {
               cacheServer = new TcpCacheServer();
               cacheServer.setBindAddress(TCP_CACHE_SERVER_HOST);
               cacheServer.setPort(TCP_CACHE_SERVER_PORT);
               Configuration config = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
               // disable eviction!!
               config.setEvictionConfig(null);
               CacheSPI cache = (CacheSPI) new UnitTestCacheFactory<Object, Object>().createCache(config, getClass());
               cacheServer.setCache(cache);
               cacheServer.create();
               cacheServer.start();
               START_COUNT++;
               startedSignal.countDown();
            }
            catch (Exception ex)
            {
               ex.printStackTrace();
            }
         }

      };
      t.setDaemon(true);
      t.start();

      // Wait for the cache server to start up.
      boolean started = false;
      try
      {
         started = startedSignal.await(120, TimeUnit.SECONDS);
      }
      catch (InterruptedException e)
      {
         // do nothing
      }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        this.MOD=num_threads * num_msgs / 10;

        MySender[] senders=new MySender[num_threads];
        JChannel ch=new JChannel(props);
        JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), "jgroups", GROUP, true);
        final CountDownLatch latch=new CountDownLatch(1);
        MyReceiver receiver=new MyReceiver(latch);
        ch.setReceiver(receiver);
        ch.connect(GROUP);

        System.out.println("Waiting for " + num_mbrs + " members");
        latch.await();
        View view=ch.getView();
        Address local_addr=ch.getAddress();
        Address dest=pickNextMember(view, local_addr);
        System.out.println("View is " + view + "\n" + num_threads + " threads are sending " + num_msgs + " messages (of " + size + " bytes) to " + dest);

View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        final AckReceiverWindow win=new AckReceiverWindow(1, segment_size);
        final AtomicInteger counter=new AtomicInteger(num_msgs);
        final AtomicLong seqno=new AtomicLong(1);
        final AtomicInteger removed_msgs=new AtomicInteger(0);

        final CountDownLatch latch=new CountDownLatch(1);
        Adder[] adders=new Adder[num_threads];
        for(int i=0; i < adders.length; i++) {
            adders[i]=new Adder(win, latch, counter, seqno, removed_msgs);
            adders[i].start();
        }

        long start=System.currentTimeMillis();
        latch.countDown(); // starts all adders

        for(Adder adder: adders) {
            try {
                adder.join();
            }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        conn.createStatement().execute("create table test(id int primary key, value int)");
        conn.createStatement().execute("insert into test values(0, 0)");
        final int count = 1000;
        Task[] tasks = new Task[len];

        final CountDownLatch latch = new CountDownLatch(len);

        for (int i = 0; i < len; i++) {
            final int x = i;
            tasks[i] = new Task() {
                public void call() throws Exception {
                    for (int a = 0; a < count; a++) {
                        connList[x].createStatement().execute("update test set value=value+1");
                        latch.countDown();
                        latch.await();
                    }
                }
            };
            tasks[i].execute();
        }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

       c=createSharedChannel(SINGLETON_1);
       r3=new MyReceiver("c");
       c.setReceiver(r3);
      
       CountDownLatch startLatch = new CountDownLatch(1);
       CountDownLatch finishLatch = new CountDownLatch(3);
      
       ConnectTask connectA = new ConnectTask(a, "a", startLatch, finishLatch);
       Thread threadA = new Thread(connectA);
       threadA.setDaemon(true);
       threadA.start();
      
       ConnectTask connectB = new ConnectTask(b, "b", startLatch, finishLatch);
       Thread threadB = new Thread(connectB);
       threadB.setDaemon(true);
       threadB.start();
      
       ConnectTask connectC = new ConnectTask(c, "c", startLatch, finishLatch);
       Thread threadC = new Thread(connectC);
       threadC.setDaemon(true);
       threadC.start();
      
       startLatch.countDown();
      
       try
       {
          boolean finished = finishLatch.await(20, TimeUnit.SECONDS);
         
          if (connectA.exception != null)
          {
             AssertJUnit.fail("connectA threw exception " + connectA.exception);
          }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        c2=createChannel(c1);
        c2.connect("testConcurrentFlush");

        assertViewsReceived(c1, c2);

        final CountDownLatch startFlushLatch=new CountDownLatch(1);
        final CountDownLatch stopFlushLatch=new CountDownLatch(1);
        final CountDownLatch flushStartReceived=new CountDownLatch(2);
        final CountDownLatch flushStopReceived=new CountDownLatch(2);

        Thread t1=new Thread() {
            public void run() {
                try {
                    startFlushLatch.await();
                    boolean rc=Util.startFlush(c1);
                    System.out.println("t1: rc=" + rc);
                }
                catch(InterruptedException e) {
                    interrupt();
                }

                try {
                    stopFlushLatch.await();
                }
                catch(InterruptedException e) {
                    interrupt();
                }
                finally {
                    c1.stopFlush();
                }
            }
        };

        Thread t2=new Thread() {
            public void run() {
                try {
                    startFlushLatch.await();
                    boolean rc=Util.startFlush(c2);
                    System.out.println("t2: rc=" + rc);
                }
                catch(InterruptedException e) {
                    interrupt();
                }

                try {
                    stopFlushLatch.await();
                }
                catch(InterruptedException e) {
                    interrupt();
                }
                finally {
                    c2.stopFlush();
                }
            }
        };

        Listener l1=new Listener("c1", c1, flushStartReceived, flushStopReceived);
        Listener l2=new Listener("c2", c2, flushStartReceived, flushStopReceived);
        t1.start();
        t2.start();

        startFlushLatch.countDown();

        assertTrue(flushStartReceived.await(60, TimeUnit.SECONDS));

        // at this stage both channels should have started a flush
        stopFlushLatch.countDown();

        t1.join();
        t2.join();

        assertTrue(flushStopReceived.await(60, TimeUnit.SECONDS));


        assert l1.blockReceived;
        assert l1.unblockReceived;
        assert l2.blockReceived;
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

        c3=createChannel(c1);
        c3.connect("testConcurrentFlushAndPartialFlush");
        assertViewsReceived(c1, c2, c3);

        final CountDownLatch startFlushLatch=new CountDownLatch(1);
        final CountDownLatch stopFlushLatch=new CountDownLatch(1);

        // 2 because either total or partial has to finish first
        final CountDownLatch flushStartReceived=new CountDownLatch(2);

        // 5 because we have total and partial flush
        final CountDownLatch flushStopReceived=new CountDownLatch(5);

        Thread t1=new Thread() {
            public void run() {
                try {
                    startFlushLatch.await();
                    boolean rc=Util.startFlush(c1);
                    System.out.println("t1: rc=" + rc);
                }
                catch(InterruptedException e) {
                    interrupt();
                }

                try {
                    stopFlushLatch.await();
                }
                catch(InterruptedException e) {
                    interrupt();
                }
                finally {
                    c1.stopFlush();
                }
            }
        };

        Thread t2=new Thread() {
            public void run() {
                try {
                    startFlushLatch.await();
                    // partial, only between c2 and c3
                    boolean rc=Util.startFlush(c2, (Arrays.asList(c2.getLocalAddress(), c3.getLocalAddress())));
                    System.out.println("t2: partial flush rc=" + rc);
                }
                catch(InterruptedException e) {
                    interrupt();
                }

                try {
                    stopFlushLatch.await();
                }
                catch(InterruptedException e) {
                    interrupt();
                }
                finally {
                    c2.stopFlush(Arrays.asList(c2.getLocalAddress(), c3.getLocalAddress()));
                }
            }
        };

        Listener l1=new Listener("c1", c1, flushStartReceived, flushStopReceived);
        Listener l2=new Listener("c2", c2, flushStartReceived, flushStopReceived);
        Listener l3=new Listener("c3", c3, flushStartReceived, flushStopReceived);

        t1.start();
        t2.start();

        startFlushLatch.countDown();

        assertTrue(flushStartReceived.await(60, TimeUnit.SECONDS));

        // at this stage both channels should have started a flush?
        stopFlushLatch.countDown();

        t1.join();
        t2.join();

        assertTrue(flushStopReceived.await(60, TimeUnit.SECONDS));

        assert l1.blockReceived;
        assert l1.unblockReceived;
        assert l2.blockReceived;
        assert l2.unblockReceived;
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

  @Test
  public void shouldInitializeOnce() throws Exception {
    final CallTrackingMapper mapper = new CallTrackingMapper();
    ExecutorService executorService = Executors.newFixedThreadPool(10);

    final CountDownLatch latch = new CountDownLatch(THREAD_COUNT);

    HashSet<Callable<Object>> callables = new HashSet<Callable<Object>>();

    for (int i = 0; i < THREAD_COUNT; i++) {
      callables.add(new Callable<Object>() {
        public Object call() throws Exception {
          latch.countDown();
          latch.await();
          Mapper processor = mapper.getMappingProcessor();
          assertNotNull(processor);
          return null;
        }
      });
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

  }

  @Test
  public void shouldBeThreadSafe() throws Exception {
    mapper.setMappingFiles(Arrays.asList("dozerBeanMapping.xml"));
    final CountDownLatch latch = new CountDownLatch(THREAD_COUNT);

    for (int i = 0; i < THREAD_COUNT; i++) {
      new Thread(new Runnable() {
        public void run() {
          try {
            mapper.map(new TestObject(), TestObjectPrime.class);
          }
          finally {
            latch.countDown();
          }
        }
      }).start();

    }
    latch.await();
    assertTrue(exceptions.isEmpty());
  }
View Full Code Here

Examples of java.util.concurrent.CountDownLatch

    }

    public void execute(WorkerProcessContext workerProcessContext) {
        LOGGER.info("{} executing tests.", workerProcessContext.getDisplayName());

        completed = new CountDownLatch(1);

        System.setProperty(WORKER_ID_SYS_PROPERTY, workerProcessContext.getWorkerId().toString());
       
        ObjectConnection serverConnection = workerProcessContext.getServerConnection();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.