You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by GitBox <gi...@apache.org> on 2019/01/28 08:15:04 UTC

[GitHub] michaelandrepearce commented on issue #2524: ARTEMIS-2240 ActiveMQThreadPoolExecutor should use LinkedTransferQueue

michaelandrepearce commented on issue #2524: ARTEMIS-2240 ActiveMQThreadPoolExecutor should use LinkedTransferQueue
URL: https://github.com/apache/activemq-artemis/pull/2524#issuecomment-458033744
 
 
   I am see a perf gain, in commit 1, i see if anything (its a micro second here or there) negative on commit 2.
   
   I actually found something positive though, if you take the master version that we recently reverted as it kept adding new threads, vs trying to see if a thread was idle.
   
   Change it to LinkedTransferQueue and then in the offer section, which it was just returning false and the core perf issue with it. And instead use your tryTransfer(runnable) which is available with switching to LinkedTransferQueue, this actually seems to be really good, as in it now will send a runnable to a idle thread, (e.g. tryTransfer) but also becomes very lock less, a simpler code, which i guess what it was trying to achieve.
   
   sample:
   
   
   ```
   /*
    * ActiveMQThreadPoolExecutor: a special ThreadPoolExecutor that combines
    * the benefits of a cached executor and a fixed size executor.
    * Similar to a cached executor, threads exceeding the core size are only created on demand,
    * and will be removed after idling for a specified keep time.
    * But in contrast to a standard cached executor, tasks are queued if the
    * maximum pool size if reached, instead of rejected.
    */
   public class ActiveMQThreadPoolExecutor extends ThreadPoolExecutor {
   
      // Handler executed when a task is submitted and a new thread cannot be created (because maxSize was reached)
      // It queues the task on the executors's queue (using the add() method, see ThreadPoolQueue class below)
      private static final RejectedExecutionHandler QUEUE_EXECUTION_HANDLER = (r, e) -> {
         if (!e.isShutdown()) {
            e.getQueue().add(r);
         }
      };
   
      // A specialized LinkedBlockingQueue that takes new elements by calling add() but not offer()
      // This is to force the ThreadPoolExecutor to always create new threads and never queue
      private static class ThreadPoolQueue extends LinkedTransferQueue<Runnable> {
   
         @Override
         public boolean offer(Runnable runnable) {
            return tryTransfer(runnable);
         }
   
         @Override
         public boolean add(Runnable runnable) {
            return super.offer( runnable );
         }
      }
   
      public ActiveMQThreadPoolExecutor(int coreSize, int maxSize, long keep, TimeUnit keepUnits, ThreadFactory factory) {
         super( coreSize, maxSize, keep, keepUnits, new ThreadPoolQueue(), factory, QUEUE_EXECUTION_HANDLER );
      }
   }
   
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services