Version 10

    Configuration of a BasicThreadPool

     

    The basic thread pool provides a simple thread pooling service

     

    Example Configuration

      <mbean code="org.jboss.util.threadpool.BasicThreadPool" name="jboss.jca:service=WorkManagerThreadPool">
         <!-- The name that appears in thread names -->
         <attribute name="Name">WorkManager</attribute>
         <!-- The maximum amount of work in the queue -->
         <attribute name="MaximumQueueSize">1024</attribute>
         <!-- The maximum number of active threads -->
         <attribute name="MaximumPoolSize">100</attribute>
         <!-- How long to keep threads alive after their last work (default one minute) -->
         <attribute name="KeepAliveTime">60000</attribute>
      </mbean>
    

     

    Configurable Attributes

    • Name
      - the name that appears on threads in the pool (default

      ThreadPool

      )

    • MaximumQueueSize
      - the maximum number of requests that are waiting to be executed (default 1024)

    • MinimumPoolSize
      - the minimum number of threads to keep active, the pool is not prefilled (default 0 - zero)

    • MaximumPoolSize
      - the maximum number of threads that are active (default 100)

    • BlockingMode
      - the behaviour when the queue is full (default abort)

      • abort
        - a RuntimeException is thrown

      • run
        - the calling thread executes the task

      • wait
        - the calling thread blocks until the queue has room. IMPORTANT: The
        MinimumPoolSize
        must be > 0 (zero) for this configuration

      • discard
        - the task is silently discarded without being run

      • discardOldest
        - check to see if a task is about to complete and enque the new task if possible, else run the task in the calling thread

    • KeepAliveTime
      - how long to keep threads when there is nothing to do in milli-seconds (default 60000 == 1 minute)

    • ThreadGroupName
      - the thread group the threads are created in (default

      JBoss Pooled Threads

      )

     

    Informational

    • Queue
      - the current queue size

    • PoolNumber
      - the internal thread pool number

    • Instance
      - the thread pool instance(org.jboss.util.threadpool.ThreadPool)

    /*
      * JBoss, Home of Professional Open Source
      * Copyright 2005, JBoss Inc., and individual contributors as indicated
      * by the @authors tag. See the copyright.txt in the distribution for a
      * full listing of individual contributors.
      *
      * This is free software; you can redistribute it and/or modify it
      * under the terms of the GNU Lesser General Public License as
      * published by the Free Software Foundation; either version 2.1 of
      * the License, or (at your option) any later version.
      *
      * This software is distributed in the hope that it will be useful,
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      * Lesser General Public License for more details.
      *
      * You should have received a copy of the GNU Lesser General Public
      * License along with this software; if not, write to the Free
      * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
      * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
      */
    package org.jboss.util.threadpool;
    
    /**
     * A thread pool.
     *
     * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
     * @version $Revision: 1.5 $
     */
    public interface ThreadPool
    {
       // Constants -----------------------------------------------------
    
       // Public --------------------------------------------------------
    
       /**
        * Stop the pool
        *
        * @param immediate whether to shutdown immediately
        */
       public void stop(boolean immediate);
    
       /** Wait on the queued tasks to complete. This can only be called after
        * after stop.
        * 
        * @throws InterruptedException
        */ 
       public void waitForTasks() throws InterruptedException;
    
       /** Wait on the queued tasks to complete upto maxWaitTime milliseconds. This
        * can only be called after after stop.
        * 
        * @param maxWaitTime
        * @throws InterruptedException
        */ 
       public void waitForTasks(long maxWaitTime) throws InterruptedException;
    
       /**
        * Run a task wrapper
        *
        * @param wrapper the task wrapper
        */
       public void runTaskWrapper(TaskWrapper wrapper);
    
       /**
        * Run a task
        *
        * @param task the task
        * @throws IllegalArgumentException for a null task
        */
       public void runTask(Task task);
    
       /**
        * Run a runnable
        *
        * @param runnable the runnable
        * @throws IllegalArgumentException for a null runnable
        */
       public void run(Runnable runnable);
    
       /**
        * 
        * @param runnable
        * @param startTimeout
        * @param completeTimeout
        */ 
       public void run(Runnable runnable, long startTimeout, long completeTimeout);
    }