Package org.jboss.util.threadpool

Examples of org.jboss.util.threadpool.BasicThreadPool


   }

   public void testBlockingSmallThreadPool() throws Exception
   {
      final int times = 100;
      BasicThreadPool tp = new BasicThreadPool();
      tp.setMaximumQueueSize(1);
      tp.setMaximumPoolSize(1);
      tp.setBlockingMode(BlockingMode.RUN);
      TT tt = new TT();
      TimeoutFactory tf = new TimeoutFactory(tp);
      for (int i = 0; i < times; i++)
      {
         tf.schedule(0, (TimeoutTarget)tt);
View Full Code Here


   }
  
   public void testAbortingSmallThreadPool() throws Exception
   {
      final int times = 50;
      BasicThreadPool tp = new BasicThreadPool();
      tp.setMaximumQueueSize(1);
      tp.setMaximumPoolSize(1);
      TT tt = new TT();
      TimeoutFactory tf = new TimeoutFactory(tp);
      for (int i = 0; i < times; i++)
      {
         tf.schedule(0, (TimeoutTarget)tt);
View Full Code Here

   private NonserializableClass custom2 = new NonserializableClass();
   private Element xml;

   public InvokerTest()
   {
      BasicThreadPool pool = new BasicThreadPool();
      pool.setBlockingMode(BlockingMode.RUN);
      pool.setMaximumQueueSize(20);
      pool.setMaximumPoolSize(1);
      super.setThreadPool(pool);
      /* With this set to 0, the testNotificationWithBadListener in
      JMXInvokerUnitTestCase should fail due to the BadListener blocking the
      server notification thread pool. With a value of
      */
 
View Full Code Here

   /**
    * Basic test
    */
   public void testBasic() throws Exception
   {
      BasicThreadPool pool = new BasicThreadPool();
      try
      {
         pool.runTask(new TestTask(BASIC, "test"));
         completed.wait(1);
         HashSet expected = makeExpected(new Object[] {"test"});
         assertEquals(expected, accepted.tasks);
         assertEquals(expected, started.tasks);
         assertEquals(expected, completed.tasks);
      }
      finally
      {
         pool.stop(true);
      }
   }
View Full Code Here

   /**
    * Multiple Basic test
    */
   public void testMultipleBasic() throws Exception
   {
      BasicThreadPool pool = new BasicThreadPool();
      try
      {
         pool.runTask(new TestTask(BASIC, "test1"));
         pool.runTask(new TestTask(BASIC, "test2"));
         pool.runTask(new TestTask(BASIC, "test3"));
         completed.wait(3);
         HashSet expected = makeExpected(new Object[] {"test1", "test2", "test3"});
         assertEquals(expected, accepted.tasks);
         assertEquals(expected, started.tasks);
         assertEquals(expected, completed.tasks);
      }
      finally
      {
         pool.stop(true);
      }
   }
View Full Code Here

   /**
    * Test pooling
    */
   public void testSimplePooling() throws Exception
   {
      BasicThreadPool pool = new BasicThreadPool();
      pool.setMaximumPoolSize(1);
      try
      {
         pool.runTask(new TestTask(BASIC, "test1"));
         completed.wait(1);
         pool.runTask(new TestTask(BASIC, "test2"));
         completed.wait(2);
         assertEquals(threadNames.get("test1"), threadNames.get("test2"));
      }
      finally
      {
         pool.stop(true);
      }
   }
View Full Code Here

   /**
    * Test multiple pooling
    */
   public void testMultiplePooling() throws Exception
   {
      BasicThreadPool pool = new BasicThreadPool();
      try
      {
         pool.runTask(new TestTask(HOLD_START, "test1"));
         started.wait(1);
         pool.runTask(new TestTask(BASIC, "test2"));
         completed.wait(1);
         started.release("test1");
         completed.wait(2);
         assertTrue("Shouldn't run on the same thread", threadNames.get("test1").equals(threadNames.get("test2")) == false);
      }
      finally
      {
         pool.stop(true);
      }
   }
View Full Code Here

   /**
    * Test maximum pool
    */
   public void testMaximumPool() throws Exception
   {
      BasicThreadPool pool = new BasicThreadPool();
      pool.setMaximumPoolSize(1);
      try
      {
         pool.runTask(new TestTask(HOLD_START, "test1"));
         started.wait(1);
         pool.runTask(new TestTask(BASIC, "test2"));
         Thread.sleep(1000);
         assertEquals(0, completed.tasks.size());
         started.release("test1");
         completed.wait(2);
         assertEquals(makeExpected(new Object[] {"test1", "test2"}), completed.tasks);
      }
      finally
      {
         pool.stop(true);
      }
   }
View Full Code Here

   /**
    * Test maximum cache
    */
   public void testMaximumQueue() throws Exception
   {
      BasicThreadPool pool = new BasicThreadPool();
      pool.setMaximumQueueSize(1);
      pool.setMaximumPoolSize(1);
      try
      {
         pool.runTask(new TestTask(HOLD_START, "test1"));
         started.wait(1);
         pool.runTask(new TestTask(BASIC, "test2"));
         assertEquals(0, rejected.tasks.size());
         pool.runTask(new TestTask(BASIC, "test3"));
         assertEquals(makeExpected(new Object[] {"test3"}), rejected.tasks);

         started.release("test1");
         completed.wait(2);
         assertEquals(makeExpected(new Object[] {"test1", "test2"}), completed.tasks);
      }
      finally
      {
         pool.stop(true);
      }
   }
View Full Code Here

   /**
    * Test maximum cache
    */
   public void testCompleteTimeout() throws Exception
   {
      BasicThreadPool pool = new BasicThreadPool();
      pool.setMaximumQueueSize(1);
      pool.setMaximumPoolSize(1);
      try
      {
         /* Test that a task with a timeout that completes within its timeout
         works as expected
         */
         TestTask task = new TestTask(HOLD_START, "test1", 0, 10*1000, Task.WAIT_NONE);
         pool.runTask(task);
         started.wait(1);
         started.release("test1");
         completed.wait(1);

         /* Test a task with a timeout that does not complete within its timeout
         is stopped
         */
         task = new TestTask(HOLD_START, "test2", 0, 10*1000, Task.WAIT_NONE);
         task.setRunSleepTime(12*1000);
         pool.runTask(task);
         started.wait(1);
         started.release("test2");
         stopped.wait(1);
         completed.wait(1);

         // Test that another valid task completes as expected
         task = new TestTask(HOLD_START, "test3", 0, 0, Task.WAIT_NONE);
         pool.runTask(task);
         started.wait(1);
         started.release("test3");
         completed.wait(1);

         /* Test a task with a timeout that does not complete within its timeout
         is stopped
         */
         task = new TestTask(HOLD_START, "test4", 0, 10*1000, Task.WAIT_NONE);
         task.setRunSleepTime(12*1000);
         pool.runTask(task);
         started.wait(1);
         started.release("test4");
         stopped.wait(1);        
         completed.wait(1);
      }
      finally
      {
         pool.stop(true);
      }
   }
View Full Code Here

TOP

Related Classes of org.jboss.util.threadpool.BasicThreadPool

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.