Package java.util.concurrent

Examples of java.util.concurrent.CountDownLatch


    * @throws Exception
    */
   public void testLifecycleWithLockedFile() throws Exception
   {
      String fileName = "jnp-service-" + count + ".url";
      tearDownLatch = new CountDownLatch(1);
      CountDownLatch lockedLatch = new CountDownLatch(1);
      FileLocker locker = new FileLocker(tempDir, fileName, null, tearDownLatch, lockedLatch);
     
      NamingProviderURLWriter testee = new NamingProviderURLWriter();
      testee.setOutputDirURL(tempDir);
      testee.setOutputFileName(fileName);
      testee.setBootstrapAddress("localhost");
      testee.setBootstrapPort(9999);
     
      Thread t = new Thread(locker);
      t.setDaemon(true);
      t.start();
      assertTrue("FileLocker locked file", lockedLatch.await(10, TimeUnit.SECONDS));
      testee.start();
      testee.stop();
   }
View Full Code Here


      }

      final int iterationCount = getIterationCount();
      final Logger log = getLog();
     
      final CountDownLatch startFlag = new CountDownLatch(1);

      Thread sendThread =
         new Thread()
         {
            /**
             * Main processing method for the JMSPerfStressTestCase object
             */
            public void run()
            {
               try
               {

                  TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
                  Topic topic = (Topic)context.lookup(TEST_TOPIC);

                  TopicPublisher publisher = session.createPublisher(topic);

                  startFlag.await();

                  BytesMessage message = session.createBytesMessage();
                  message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);

                  long startTime = System.currentTimeMillis();
                  for (int i = 0; i < iterationCount; i++)
                  {
                     publisher.publish(message, persistence, 4, 0);
                     //publisher.publish(topic, message, persistence, 4, 0);
                     //getLog().debug("  Sent #"+i);
                     if (transacted == TRANS_INDIVIDUAL)
                     {
                        session.commit();
                     }
                  }

                  if (transacted == TRANS_TOTAL)
                  {
                     session.commit();
                  }

                  long endTime = System.currentTimeMillis();
                  session.close();

                  long pTime = endTime - startTime;
                  log.debug("  sent all messages in " + ((double)pTime / 1000) + " seconds. ");
               }
               catch (Exception e)
               {
                  log.error("error", e);
               }
            }
         };

      final TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
      Topic topic = (Topic)context.lookup(TEST_TOPIC);
      TopicSubscriber subscriber = session.createSubscriber(topic);

      MessageListener listener =
         new MessageListener()
         {
            long startTime = System.currentTimeMillis();
            int i = 0;

            /**
             * #Description of the Method
             *
             * @param message  Description of Parameter
             */
            public void onMessage(Message message)
            {
               try
               {
        if( transacted == TRANS_INDIVIDUAL )
          session.commit();
                  i++;
               }
               catch (JMSException e)
               {
                  getLog().error("Unable to commit", e);
                  synchronized (this)
                  {
                     this.notify();
                  }
               }
               if (i >= iterationCount)
               {
                  long endTime = System.currentTimeMillis();
                  long pTime = endTime - startTime;
                  log.debug("  received all messages in " + ((double)pTime / 1000) + " seconds. ");

                  synchronized (this)
                  {
                     this.notify();
                  }
               }
            }
         };

      getLog().debug("  Asynch Topic: This test will send " + getIterationCount() + " "
             + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
             + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
             + " Session is " + TRANS_DESC[transacted] + " transacted");
      long startTime = System.currentTimeMillis();
      sendThread.start();
      subscriber.setMessageListener(listener);
      startFlag.countDown();
      synchronized (listener)
      {
         topicConnection.start();
         listener.wait();
      }
View Full Code Here

         drainQueue();
      }
      final int iterationCount = getIterationCount();
      final Logger log = getLog();
     
      final CountDownLatch alignFlag = new CountDownLatch(2);
     

      Thread sendThread =
         new Thread("sendThread transacted = " + transacted + " persistent = " + persistence)
         {
            /**
             * Main processing method for the JBossMQPerfStressTestCase object
             */
            public void run()
            {
               try
               {

                  TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
                  Topic topic = (Topic)context.lookup(TEST_TOPIC);

                  TopicPublisher publisher = session.createPublisher(topic);

                  alignFlag.countDown();
                  alignFlag.await();

                  BytesMessage message = session.createBytesMessage();
                  message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);

                  long startTime = System.currentTimeMillis();
                  for (int i = 0; i < iterationCount; i++)
                  {
                     publisher.publish(message, persistence, 4, 0);
                     //publisher.publish(topic, message, persistence, 4, 0);
                     //getLog().debug("  Sent #"+i);
                     if (transacted == TRANS_INDIVIDUAL)
                     {
                        session.commit();
                     }
                  }

                  if (transacted == TRANS_TOTAL)
                  {
                     session.commit();
                  }

                  long endTime = System.currentTimeMillis();

                  session.close();

                  long pTime = endTime - startTime;
                  log.debug("  sent all messages in " + ((double)pTime / 1000) + " seconds. ");
               }
               catch (Exception e)
               {
                  log.error("error", e);
               }
            }
         };

      Thread recvThread =
         new Thread("recvThread transacted = " + transacted + " persistent = " + persistence)
         {
            /**
             * Main processing method for the JBossMQPerfStressTestCase object
             */
            public void run()
            {
               try
               {

                  TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
                  Topic topic = (Topic)context.lookup(TEST_TOPIC);
                  TopicSubscriber subscriber = session.createSubscriber(topic);

                  alignFlag.countDown();
                  alignFlag.await();

                  long startTime = System.currentTimeMillis();
                  for (int i = 0; i < iterationCount; i++)
                  {
                     subscriber.receive();
View Full Code Here

    final SLDParser parser = new SLDParser(factory, pii);

    IMarshallingContext mctx = bfact.createMarshallingContext();
    mctx.setOutput(new PrintWriter(pos));

    CountDownLatch countDown = new CountDownLatch(2);
    ArrayList<Style> styles = new ArrayList<Style>();
    new Thread(new Parser(countDown, parser, styles)).start();
    new Thread(new Marshaller(countDown, mctx, sld)).start();
    countDown.await();

    Assert.assertEquals("GEOSYM", styles.get(0).getName());
  }
View Full Code Here

         if (execContext == null)
         {
            execContext = new ExecutionContext()
         }

         final CountDownLatch completedLatch = new CountDownLatch(1);

         wrapper = new WorkWrapper(this, work, execContext, workListener, null, completedLatch);

         if (workListener != null)
         {
            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
            workListener.workAccepted(event);
         }

         BlockingExecutor executor = getExecutor(work);

         if (startTimeout == WorkManager.INDEFINITE)
         {
            executor.executeBlocking(wrapper);
         }
         else
         {
            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
         }

         completedLatch.await();
      }
      catch (ExecutionTimedOutException etoe)
      {
         exception = new WorkRejectedException(etoe);
         exception.setErrorCode(WorkRejectedException.START_TIMED_OUT)
View Full Code Here

         if (execContext == null)
         {
            execContext = new ExecutionContext()
         }

         final CountDownLatch startedLatch = new CountDownLatch(1);

         wrapper = new WorkWrapper(this, work, execContext, workListener, startedLatch, null);

         if (workListener != null)
         {
            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
            workListener.workAccepted(event);
         }

         BlockingExecutor executor = getExecutor(work);

         if (startTimeout == WorkManager.INDEFINITE)
         {
            executor.executeBlocking(wrapper);
         }
         else
         {
            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
         }

         startedLatch.await();

         return System.currentTimeMillis() - started;
      }
      catch (ExecutionTimedOutException etoe)
      {
View Full Code Here

      setupQueue();
      // FIXME This test fails after 5 iterations with JBoss Messaging
      for (int i = 0; i < 4; ++i)
      {
         log.info("Running " + getName() + " iteration=" + i);
         latch = new CountDownLatch(2);

         ExecuteJMS executeJMS = new ExecuteJMS();
         Thread thread1 = new Thread(executeJMS);
         thread1.start();
View Full Code Here

      final TxConnectionManager cm = getCM(pp, trackByTx);

      try
      {
         int totalThreads = pp.maxSize * threadsPerConnection;
         finishedThreadCount = new CountDownLatch(totalThreads);

         log.info("Blocking test with connections: " + pp.maxSize + " totalThreads: " + totalThreads + " reps: " + reps);
         for (int i = 0; i < totalThreads; i++)
         {
            Runnable t = new Runnable()
View Full Code Here

      final TxConnectionManager cm = getCM(pp, trackByTx);

      try
      {
         int totalThreads = pp.maxSize * threadsPerConnection;
         finishedThreadCount = new CountDownLatch(totalThreads);

         log.info("Timeout test with connections: " + pp.maxSize + " totalThreads: " + totalThreads + " reps: " + reps);
         for (int i = 0; i < totalThreads; i++)
         {
            Runnable t = new TestRunnable(reps, cm, trackByTx);
View Full Code Here

   {
      dataSource = (DataSource) new InitialContext().lookup("java:DefaultDS");
      createDatabase();
      for (int i = 0; i < getIterationCount(); ++i)
      {
         latch = new CountDownLatch(2);

         ExecuteSQL executeSQL = new ExecuteSQL();
         Thread thread1 = new Thread(executeSQL);
         thread1.start();
View Full Code Here

TOP

Related Classes of java.util.concurrent.CountDownLatch

Copyright © 2018 www.massapicom. 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.