You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/08/08 02:36:27 UTC

cvs commit: jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/thread/impl/test DefaultThreadPoolTestCase.java

bloritsch    2002/08/07 17:36:27

  Modified:    event    build.xml default.properties
               event/src/java/org/apache/excalibur/event
                        FixedSizeQueue.java
               event/src/java/org/apache/excalibur/event/command
                        AbstractThreadManager.java
                        DefaultThreadManager.java TPCThreadManager.java
                        TPSPThreadManager.java
               event/src/java/org/apache/excalibur/mpool Pool.java
               event/src/test/org/apache/excalibur/mpool/test
                        MultiThreadedPoolComparisonProfile.java
  Added:       event/src/java/org/apache/excalibur/thread
                        ThreadControl.java ThreadPool.java
               event/src/java/org/apache/excalibur/thread/impl
                        DefaultThreadControl.java DefaultThreadPool.java
                        ExecutableRunnable.java WorkerThread.java
               event/src/test/org/apache/excalibur/thread/impl/test
                        DefaultThreadPoolTestCase.java
  Log:
  Convert Event to use its own version of pooling and Thread Pools.
  
  Revision  Changes    Path
  1.29      +21 -19    jakarta-avalon-excalibur/event/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/build.xml,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- build.xml	7 Aug 2002 16:34:55 -0000	1.28
  +++ build.xml	8 Aug 2002 00:36:26 -0000	1.29
  @@ -14,12 +14,8 @@
           <pathelement location="${build.classes}"/>
           <pathelement location="${excalibur-collections.jar}"/>
           <pathelement location="${excalibur-concurrent.jar}"/>
  -        <pathelement location="${excalibur-thread.jar}"/>
           <pathelement location="${excalibur-threadcontext.jar}"/>
  -        <pathelement location="${excalibur-pool.jar}"/>
           <pathelement location="${excalibur-scratchpad.jar}"/>
  -        <pathelement location="${excalibur-core.jar}"/>
  -        <pathelement location="${excalibur-instrument.jar}"/>
           <pathelement location="${avalon-framework.jar}"/>
           <pathelement location="${excalibur-util.jar}"/>
           <pathelement location="${checkstyle.jar}"/>
  @@ -34,6 +30,10 @@
       </path>
   
       <path id="test.class.path">
  +        <pathelement location="${excalibur-pool.jar}"/>
  +        <pathelement location="${excalibur-instrument.jar}"/>
  +        <pathelement location="${logkit.jar}"/>
  +        <pathelement location="${excalibur-testcase.jar}"/>
           <pathelement location="${build.testclasses}"/>
           <pathelement location="${junit.jar}"/>
           <path refid="project.class.path"/>
  @@ -46,17 +46,19 @@
       <target name="dependencies" description="Check dependencies" unless="skip.dependencies">
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCommon"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCollections"/>
  -	<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkConcurrent"/>
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkConcurrent"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkUtil"/>
  -        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkThread"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkThreadcontext"/>
  -        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkPool"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkFramework"/>
       </target>
   
       <target name="dependencies-test" depends="dist-jar, dependencies"
           description="Check unit test dependencies" unless="skip.dependencies">
           <!-- Need the jar to prevent recursive deps. -->
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkTestcase"/>
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkLogkit"/>
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkInstrument"/>
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkPool"/>
   
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkJUnit"/>
       </target>
  @@ -305,8 +307,8 @@
               <fileset dir="${build.lib}">
                   <include name="*.jar"/>
               </fileset>
  -        </copy> 
  -    </target>   
  +        </copy>
  +    </target>
   
       <!-- Creates a minimal distribution -->
       <target name="dist.lite"
  @@ -344,8 +346,8 @@
         <filter token="LOGKIT_BASE" value="${logkit.base}"/>
         <filter token="TESTLET_BASE" value="${testlet.base}"/>
       </target>
  -    
  -    
  +
  +
       <!-- Prepares the documentation directory -->
       <target name="docs" depends="setup-filters" description="Generates the Docs">
         <mkdir dir="${docs.dir}"/>
  @@ -356,22 +358,22 @@
           <fileset dir="${build.docs}">
             <include name="**"/>
           </fileset>
  -      </copy>    
  +      </copy>
   
         <!-- hack for stupid transport on api link -->
         <replace file="${docs.dir}/index.html" token="index.html.xml" value="index.html"/>
  -     
  +
       </target>
  -    
  -    <target name="site" depends="javadocs, docs" description=" Places Docs ready for hosting on website">  
  -  
  -      <mkdir dir="../site/dist/docs/${dir-name}"/>     
  +
  +    <target name="site" depends="javadocs, docs" description=" Places Docs ready for hosting on website">
  +
  +      <mkdir dir="../site/dist/docs/${dir-name}"/>
         <copy todir="../site/dist/docs/${dir-name}">
           <fileset dir="${docs.dir}">
             <include name="**"/>
           </fileset>
  -      </copy>        
  -  
  +      </copy>
  +
       </target>
   
       <!-- Cleans up build and distribution directories -->
  
  
  
  1.14      +130 -128  jakarta-avalon-excalibur/event/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/default.properties,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- default.properties	7 Aug 2002 22:44:25 -0000	1.13
  +++ default.properties	8 Aug 2002 00:36:26 -0000	1.14
  @@ -1,128 +1,130 @@
  -# -------------------------------------------------------------------
  -# B U I L D  P R O P E R T I E S
  -# -------------------------------------------------------------------
  -# Specifies default property values
  -# Overridden by ../default.properties and all ant.properties
  -# Not user-editable; use ant.properties files instead
  -
  -name=excalibur-event
  -Name=Excalibur Event
  -dir-name=event
  -version=1.0a
  -package-version=0.99
  -year=2002
  -
  -# --------------------------------------------------
  -#                REQUIRED LIBRARIES
  -# --------------------------------------------------
  -# ----- Excalibur util, version 1.0 or later -----
  -excalibur-util.home=${basedir}/../util/dist
  -excalibur-util.lib=${excalibur-util.home}
  -excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  -
  -# ----- Excalibur thread, version 1.0 or later -----
  -excalibur-thread.home=${basedir}/../thread/dist
  -excalibur-thread.lib=${excalibur-thread.home}
  -excalibur-thread.jar=${excalibur-thread.lib}/excalibur-thread-1.0.jar
  -
  -# ----- Excalibur threadcontext, version 1.0 or later -----
  -excalibur-threadcontext.home=${basedir}/../threadcontext/dist
  -excalibur-threadcontext.lib=${excalibur-threadcontext.home}
  -excalibur-threadcontext.jar=${excalibur-threadcontext.lib}/excalibur-threadcontext-1.0.jar
  -
  -# ----- Excalibur Collections, version 1.0 or later -----
  -excalibur-collections.home=${basedir}/../collections/dist
  -excalibur-collections.lib=${excalibur-collections.home}
  -excalibur-collections.jar=${excalibur-collections.lib}/excalibur-collections-1.0.jar
  -
  -# ----- Excalibur Concurrent, version 1.0 or later -----
  -excalibur-concurrent.home=${basedir}/../concurrent/dist
  -excalibur-concurrent.lib=${excalibur-concurrent.home}
  -excalibur-concurrent.jar=${excalibur-concurrent.lib}/excalibur-concurrent-1.0.jar
  -
  -# ----- Excalibur Pool, version 1.1 or later -----
  -excalibur-pool.home=${basedir}/../pool/dist
  -excalibur-pool.lib=${excalibur-pool.home}
  -excalibur-pool.jar=${excalibur-pool.lib}/excalibur-pool-1.1.jar
  -
  -# ----- Excalibur Util, version 1.0 or later -----
  -excalibur-util.home=${basedir}/../util/build/lib
  -excalibur-util.lib=${excalibur-util.home}
  -excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  -
  -# ----- Excalibur Scratchpad -----
  -excalibur-scratchpad.home=${basedir}/../all
  -excalibur-scratchpad.lib=${excalibur-scratchpad.home}/build/lib
  -excalibur-scratchpad.jar=${excalibur-scratchpad.lib}/excalibur-scratchpad.jar
  -
  -# ----- Excalibur Core -----
  -excalibur-core.home=${basedir}/../all
  -excalibur-core.lib=${excalibur-core.home}/build/lib
  -excalibur-core.jar=${excalibur-core.lib}/excalibur-core.jar
  -
  -# ----- Avalon Framework, version 4.1 or later -----
  -avalon-framework.home=${basedir}/../../jakarta-avalon
  -avalon-framework.lib=${avalon-framework.home}/build/lib
  -avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
  -
  -# --------------------------------------------------
  -#          REQUIRED LIBRARIES FOR UNIT TESTS
  -# --------------------------------------------------
  -
  -# For unit testing
  -
  -# ----- Excalibur instrument, version 0.2 or later -----
  -excalibur-instrument.home=${basedir}/../instrument/dist
  -excalibur-instrument.lib=${excalibur-instrument.home}
  -excalibur-instrument.jar=${excalibur-instrument.lib}/excalibur-instrument-0.3.jar
  -
  -# --------------------------------------------------
  -
  -#  Settings used to configure compile environment
  -build.debug = on
  -build.optimize = off
  -build.deprecation = off
  -build.compress = false
  -junit.failonerror = false
  -
  -#  location of intermediate products
  -build.dir = build
  -build.testsrc = ${build.dir}/testsrc
  -build.testclasses = ${build.dir}/testclasses
  -build.lib = ${build.dir}/lib
  -build.conf = ${build.dir}/conf
  -build.classes = ${build.dir}/classes
  -build.tests = ${build.dir}/tests
  -build.reports = ${build.dir}/reports
  -
  -#  Set the properties for source directories
  -src.dir = src
  -java.dir = ${src.dir}/java
  -conf.dir = ${src.dir}/conf
  -test.dir = ${src.dir}/test
  -
  -#  needed by Cocoon
  -build.context = ${build.dir}/documentation
  -build.docs = ${build.dir}/docs
  -build.xdocs = ${build.dir}/xdocs
  -context.dir = ../../jakarta-avalon/src/documentation
  -tools.dir = ../../jakarta-avalon/tools
  -tools.jar = ${java.home}/../lib/tools.jar
  -docs.dir = docs
  -xdocs.dir = ${src.dir}/xdocs
  -
  -#  Set the properties for distribution directories
  -dist.dir = dist
  -dist.javadocs = ${docs.dir}/api
  -
  -#  name of .zip/.tar.gz/.bz2 files and their top-level directory
  -dist.name = ${name}-${version}
  -
  -#  name of jar file
  -jar.name = ${name}-${version}.jar
  -
  -#  property indicating directory where all distribution archives are placed
  -dist.base = distributions
  -
  -depchecker.prefix=.
  -
  +# -------------------------------------------------------------------
  +# B U I L D  P R O P E R T I E S
  +# -------------------------------------------------------------------
  +# Specifies default property values
  +# Overridden by ../default.properties and all ant.properties
  +# Not user-editable; use ant.properties files instead
  +
  +name=excalibur-event
  +Name=Excalibur Event
  +dir-name=event
  +version=1.0a
  +package-version=0.99
  +year=2002
  +
  +# --------------------------------------------------
  +#                REQUIRED LIBRARIES
  +# --------------------------------------------------
  +# ----- Excalibur util, version 1.0 or later -----
  +excalibur-util.home=${basedir}/../util/dist
  +excalibur-util.lib=${excalibur-util.home}
  +excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  +
  +# ----- Excalibur threadcontext, version 1.0 or later -----
  +excalibur-threadcontext.home=${basedir}/../threadcontext/dist
  +excalibur-threadcontext.lib=${excalibur-threadcontext.home}
  +excalibur-threadcontext.jar=${excalibur-threadcontext.lib}/excalibur-threadcontext-1.0.jar
  +
  +# ----- Excalibur Collections, version 1.0 or later -----
  +excalibur-collections.home=${basedir}/../collections/dist
  +excalibur-collections.lib=${excalibur-collections.home}
  +excalibur-collections.jar=${excalibur-collections.lib}/excalibur-collections-1.0.jar
  +
  +# ----- Excalibur Concurrent, version 1.0 or later -----
  +excalibur-concurrent.home=${basedir}/../concurrent/dist
  +excalibur-concurrent.lib=${excalibur-concurrent.home}
  +excalibur-concurrent.jar=${excalibur-concurrent.lib}/excalibur-concurrent-1.0.jar
  +
  +# ----- Excalibur Util, version 1.0 or later -----
  +excalibur-util.home=${basedir}/../util/build/lib
  +excalibur-util.lib=${excalibur-util.home}
  +excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
  +
  +# ----- Excalibur Core -----
  +excalibur-core.home=${basedir}/../all
  +excalibur-core.lib=${excalibur-core.home}/build/lib
  +excalibur-core.jar=${excalibur-core.lib}/excalibur-core.jar
  +
  +# ----- Avalon Framework, version 4.1 or later -----
  +avalon-framework.home=${basedir}/../../jakarta-avalon
  +avalon-framework.lib=${avalon-framework.home}/build/lib
  +avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
  +
  +# --------------------------------------------------
  +#          REQUIRED LIBRARIES FOR UNIT TESTS
  +# --------------------------------------------------
  +
  +# For unit testing
  +
  +# ----- Excalibur Testcase, version 1.0 or later -----
  +excalibur-testcase.home=${basedir}/../testcase/dist
  +excalibur-testcase.lib=${excalibur-testcase.home}
  +excalibur-testcase.jar=${excalibur-testcase.lib}/excalibur-testcase-1.0.jar
  +
  +# ----- Excalibur Pool, version 1.0 or later -----
  +excalibur-pool.home=${basedir}/../pool/dist
  +excalibur-pool.lib=${excalibur-pool.home}
  +excalibur-pool.jar=${excalibur-pool.lib}/excalibur-pool-1.1.jar
  +
  +# ----- Logkit -----
  +logkit.home=${basedir}/../../jakarta-avalon-logkit
  +logkit.lib=${logkit.home}/build/lib
  +logkit.jar=${logkit.lib}/logkit.jar
  +
  +# ----- Excalibur instrument, version 1.0 or later -----
  +excalibur-instrument.home=${basedir}/../instrument/dist
  +excalibur-instrument.lib=${excalibur-instrument.home}
  +excalibur-instrument.jar=${excalibur-instrument.lib}/excalibur-instrument-0.3.jar
  +excalibur-instrument-manager.jar=${excalibur-instrument.lib}/excalibur-instrument-manager-0.3.jar
  +excalibur-instrument-manager-interfaces.jar=${excalibur-instrument.lib}/excalibur-instrument-manager-interfaces-0.3.jar
  +
  +# --------------------------------------------------
  +
  +#  Settings used to configure compile environment
  +build.debug = on
  +build.optimize = off
  +build.deprecation = off
  +build.compress = false
  +junit.failonerror = false
  +
  +#  location of intermediate products
  +build.dir = build
  +build.testsrc = ${build.dir}/testsrc
  +build.testclasses = ${build.dir}/testclasses
  +build.lib = ${build.dir}/lib
  +build.conf = ${build.dir}/conf
  +build.classes = ${build.dir}/classes
  +build.tests = ${build.dir}/tests
  +build.reports = ${build.dir}/reports
  +
  +#  Set the properties for source directories
  +src.dir = src
  +java.dir = ${src.dir}/java
  +conf.dir = ${src.dir}/conf
  +test.dir = ${src.dir}/test
  +
  +#  needed by Cocoon
  +build.context = ${build.dir}/documentation
  +build.docs = ${build.dir}/docs
  +build.xdocs = ${build.dir}/xdocs
  +context.dir = ../../jakarta-avalon/src/documentation
  +tools.dir = ../../jakarta-avalon/tools
  +tools.jar = ${java.home}/../lib/tools.jar
  +docs.dir = docs
  +xdocs.dir = ${src.dir}/xdocs
  +
  +#  Set the properties for distribution directories
  +dist.dir = dist
  +dist.javadocs = ${docs.dir}/api
  +
  +#  name of .zip/.tar.gz/.bz2 files and their top-level directory
  +dist.name = ${name}-${version}
  +
  +#  name of jar file
  +jar.name = ${name}-${version}.jar
  +
  +#  property indicating directory where all distribution archives are placed
  +dist.base = distributions
  +
  +depchecker.prefix=.
  +
  
  
  
  1.12      +1 -1      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/FixedSizeQueue.java
  
  Index: FixedSizeQueue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/FixedSizeQueue.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FixedSizeQueue.java	7 Aug 2002 23:30:48 -0000	1.11
  +++ FixedSizeQueue.java	8 Aug 2002 00:36:26 -0000	1.12
  @@ -74,7 +74,7 @@
       public FixedSizeQueue( int size )
       {
           if ( size < 1 )
  -            throw new IllegalArgument("Cannot specify an unbounded Queue");
  +            throw new IllegalArgumentException("Cannot specify an unbounded Queue");
   
           m_elements = new QueueElement[ size + 1 ];
           m_mutex = new Mutex();
  
  
  
  1.4       +2 -2      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/AbstractThreadManager.java
  
  Index: AbstractThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/AbstractThreadManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractThreadManager.java	7 Aug 2002 23:08:26 -0000	1.3
  +++ AbstractThreadManager.java	8 Aug 2002 00:36:26 -0000	1.4
  @@ -53,8 +53,8 @@
   import java.util.Iterator;
   
   import org.apache.avalon.excalibur.concurrent.Mutex;
  -import org.apache.avalon.excalibur.thread.ThreadControl;
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  +import org.apache.excalibur.thread.ThreadControl;
  +import org.apache.excalibur.thread.ThreadPool;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  
  
  1.3       +1 -1      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/DefaultThreadManager.java
  
  Index: DefaultThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/DefaultThreadManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultThreadManager.java	7 Aug 2002 23:08:26 -0000	1.2
  +++ DefaultThreadManager.java	8 Aug 2002 00:36:26 -0000	1.3
  @@ -49,7 +49,7 @@
   */
   package org.apache.excalibur.event.command;
   
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  +import org.apache.excalibur.thread.ThreadPool;
   
   /**
    * A ThreadManager that will use an external ThreadPool. This will be useful
  
  
  
  1.24      +6 -10     jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPCThreadManager.java
  
  Index: TPCThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPCThreadManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- TPCThreadManager.java	7 Aug 2002 23:08:26 -0000	1.23
  +++ TPCThreadManager.java	8 Aug 2002 00:36:26 -0000	1.24
  @@ -53,9 +53,9 @@
   import java.util.Iterator;
   
   import org.apache.avalon.excalibur.concurrent.Mutex;
  -import org.apache.avalon.excalibur.thread.ThreadControl;
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  -import org.apache.avalon.excalibur.thread.impl.ResourceLimitingThreadPool;
  +import org.apache.excalibur.thread.ThreadControl;
  +import org.apache.excalibur.thread.ThreadPool;
  +import org.apache.excalibur.thread.impl.DefaultThreadPool;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  @@ -78,7 +78,7 @@
    */
   public final class TPCThreadManager extends AbstractThreadManager implements Parameterizable
   {
  -    private ResourceLimitingThreadPool m_tpool;
  +    private DefaultThreadPool m_tpool;
       private long m_blockTimeout = 1000L;
       private int m_processors = SystemUtil.numProcessors();
       private int m_threadsPerProcessor = 1;
  @@ -132,12 +132,8 @@
               throw new IllegalStateException( "ThreadManager is already initailized" );
           }
   
  -        m_tpool = new ResourceLimitingThreadPool( "TPCThreadManager",
  -                                                  ( m_processors * m_threadsPerProcessor ) + 1,
  -                                                  true,
  -                                                  true,
  -                                                  this.m_blockTimeout,
  -                                                  10L * 1000L );
  +        m_tpool = new DefaultThreadPool( "TPCThreadManager",
  +                                                  ( m_processors * m_threadsPerProcessor ) + 1 );
   
           if( null == getLogger() )
           {
  
  
  
  1.12      +7 -5      jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPSPThreadManager.java
  
  Index: TPSPThreadManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/event/command/TPSPThreadManager.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TPSPThreadManager.java	7 Aug 2002 23:08:26 -0000	1.11
  +++ TPSPThreadManager.java	8 Aug 2002 00:36:26 -0000	1.12
  @@ -52,9 +52,9 @@
   import java.util.HashMap;
   import java.util.Iterator;
   import org.apache.avalon.excalibur.concurrent.Mutex;
  -import org.apache.avalon.excalibur.thread.ThreadControl;
  -import org.apache.avalon.excalibur.thread.ThreadPool;
  -import org.apache.avalon.excalibur.thread.impl.ResourceLimitingThreadPool;
  +import org.apache.excalibur.thread.ThreadControl;
  +import org.apache.excalibur.thread.ThreadPool;
  +import org.apache.excalibur.thread.impl.DefaultThreadPool;
   import org.apache.excalibur.event.EventHandler;
   import org.apache.excalibur.event.Source;
   
  @@ -81,6 +81,7 @@
        * is 1.
        */
       public TPSPThreadManager()
  +    throws Exception
       {
           this( 1, 1, 1000 );
       }
  @@ -90,12 +91,13 @@
        * either value is less then one, then the value is rewritten as one.
        */
       public TPSPThreadManager( int numProcessors, int threadsPerProcessor, long sleepTime )
  +    throws Exception
       {
           int processors = Math.max( numProcessors, 1 );
           int threads = Math.max( threadsPerProcessor, 1 );
   
  -        m_threadPool = new ResourceLimitingThreadPool( "TPCThreadManager",
  -                                                       ( processors * threads ) + 1, true, true, 1000L, 10L * 1000L );
  +        m_threadPool = new DefaultThreadPool( "TPCThreadManager",
  +                                                       ( processors * threads ) + 1 );
   
           m_sleepTime = sleepTime;
           m_threadControl = m_threadPool.execute( this );
  
  
  
  1.2       +97 -96    jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/Pool.java
  
  Index: Pool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/mpool/Pool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Pool.java	7 Aug 2002 22:44:26 -0000	1.1
  +++ Pool.java	8 Aug 2002 00:36:26 -0000	1.2
  @@ -1,96 +1,97 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool;
  -
  -/**
  - * This interface is to define how a Pool is used.  We have determined by
  - * using the previous Pool implementations that the Pool marker interface
  - * is considered harmful.  When generics are introduced in JDK 1.5, this
  - * interface will be a prime candidate for those improvements.
  - *
  - * <p>
  - *  It is important to realize that some objects are cheaper to simply allow
  - *  the garbage collector to take care of them.  Therefore, only pool objects
  - *  that are computationally expensive to create.  Prime candidates would be
  - *  Components, JDBC Connection objects, Socket connections, etc.
  - * </p>
  - * <p>
  - *  The interface is inspired by both the Mutex acquire/release and the
  - *  structure of the ThreadLocal object.  In fact, it would be trivial
  - *  to implement a "ThreadLocal" pool.
  - * </p>
  - *
  - * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision$ $Date$
  - * @since 4.1.2
  - */
  -public interface Pool
  -{
  -    /**
  -     * Acquire an instance of the pooled object.
  -     *
  -     * @return the pooled Object instance
  -     */
  -    Object acquire() throws Exception;
  -
  -    /**
  -     * Release the instance of the pooled object.
  -     *
  -     * @param pooledObject  The pooled object to release to the pool.
  -     */
  -    void release( Object pooledObject );
  -
  -    /**
  -     * Create a new instance of the object being pooled.
  -     *
  -     * @return the pooled Object instance
  -     */
  -    Object newInstance() throws Exception;
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool;
  +
  +/**
  + * This interface is to define how a Pool is used.  We have determined by
  + * using the previous Pool implementations that the Pool marker interface
  + * is considered harmful.  When generics are introduced in JDK 1.5, this
  + * interface will be a prime candidate for those improvements.
  + *
  + * <p>
  + *  It is important to realize that some objects are cheaper to simply allow
  + *  the garbage collector to take care of them.  Therefore, only pool objects
  + *  that are computationally expensive to create.  Prime candidates would be
  + *  Components, JDBC Connection objects, Socket connections, etc.
  + * </p>
  + * <p>
  + *  The interface is inspired by both the Mutex acquire/release and the
  + *  structure of the ThreadLocal object.  In fact, it would be trivial
  + *  to implement a "ThreadLocal" pool.
  + * </p>
  + *
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  + * @version CVS $Revision$ $Date$
  + * @since 4.1.2
  + */
  +public interface Pool
  +{
  +    /**
  +     * Acquire an instance of the pooled object.
  +     *
  +     * @return the pooled Object instance
  +     */
  +    Object acquire() throws Exception;
  +
  +    /**
  +     * Release the instance of the pooled object.
  +     *
  +     * @param pooledObject  The pooled object to release to the pool.
  +     */
  +    void release( Object pooledObject );
  +
  +    /**
  +     * Create a new instance of the object being pooled.
  +     *
  +     * @return the pooled Object instance
  +     */
  +    Object newInstance() throws Exception;
  +}
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/ThreadControl.java
  
  Index: ThreadControl.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.thread;
  
  /**
   * This interface defines the method through which Threads can be controller.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  public interface ThreadControl
  {
      /**
       * Wait for specified time for thread to complete it's work.
       *
       * @param milliSeconds the duration in milliseconds to wait until the thread has finished work
       * @throws IllegalStateException if isValid() == false
       * @throws InterruptedException if another thread has interrupted the current thread.
       *            The interrupted status of the current thread is cleared when this exception
       *            is thrown.
       */
      void join( long milliSeconds )
          throws IllegalStateException, InterruptedException;
  
      /**
       * Call Thread.interupt() on thread being controlled.
       *
       * @throws IllegalStateException if isValid() == false
       * @throws SecurityException if caller does not have permission to call interupt()
       */
      void interupt()
          throws IllegalStateException, SecurityException;
  
      /**
       * Determine if thread has finished execution
       *
       * @return true if thread is finished, false otherwise
       */
      boolean isFinished();
  
      /**
       * Retrieve throwable that caused thread to cease execution.
       * Only valid when true == isFinished()
       *
       * @return the throwable that caused thread to finish execution
       */
      Throwable getThrowable();
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/ThreadPool.java
  
  Index: ThreadPool.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.thread;
  
  import org.apache.avalon.framework.activity.Executable;
  
  /**
   * This class is the public frontend for the thread pool code.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  public interface ThreadPool
  {
      /**
       * Run work in separate thread.
       * Return a valid ThreadControl to control work thread.
       *
       * @param work the work to be executed.
       * @return the ThreadControl
       */
      ThreadControl execute( Runnable work );
  
      /**
       * Run work in separate thread.
       * Return a valid ThreadControl to control work thread.
       *
       * @param work the work to be executed.
       * @return the ThreadControl
       */
      ThreadControl execute( Executable work );
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/impl/DefaultThreadControl.java
  
  Index: DefaultThreadControl.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.thread.impl;
  
  import org.apache.excalibur.thread.ThreadControl;
  
  /**
   * Default implementation of ThreadControl interface.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  final class DefaultThreadControl
      implements ThreadControl
  {
      ///Thread that this control is associated with
      private Thread m_thread;
  
      ///Throwable that caused thread to terminate
      private Throwable m_throwable;
  
      /**
       * Construct thread control for a specific thread.
       *
       * @param thread the thread to control
       */
      protected DefaultThreadControl( final Thread thread )
      {
          m_thread = thread;
      }
  
      /**
       * Wait for specified time for thread to complete it's work.
       *
       * @param milliSeconds the duration in milliseconds to wait until the thread has finished work
       * @throws IllegalStateException if isValid() == false
       * @throws InterruptedException if another thread has interrupted the current thread.
       *            The interrupted status of the current thread is cleared when this exception
       *            is thrown.
       */
      public synchronized void join( final long milliSeconds )
          throws IllegalStateException, InterruptedException
      {
          //final long start = System.currentTimeMillis();
          wait( milliSeconds );
          /*
            if( !isFinished() )
            {
            final long now = System.currentTimeMillis();
            if( start + milliSeconds > now )
            {
            final long remaining = milliSeconds - (now - start);
            join( remaining );
            }
            }
          */
      }
  
      /**
       * Call Thread.interrupt() on thread being controlled.
       *
       * @throws IllegalStateException if isValid() == false
       * @throws SecurityException if caller does not have permission to call interupt()
       */
      public synchronized void interupt()
          throws IllegalStateException, SecurityException
      {
          if( !isFinished() )
          {
              m_thread.interrupt();
          }
      }
  
      /**
       * Determine if thread has finished execution
       *
       * @return true if thread is finished, false otherwise
       */
      public synchronized boolean isFinished()
      {
          return ( null == m_thread );
      }
  
      /**
       * Retrieve throwable that caused thread to cease execution.
       * Only valid when true == isFinished()
       *
       * @return the throwable that caused thread to finish execution
       */
      public Throwable getThrowable()
      {
          return m_throwable;
      }
  
      /**
       * Method called by thread to release control.
       *
       * @param throwable Throwable that caused thread to complete (may be null)
       */
      protected synchronized void finish( final Throwable throwable )
      {
          m_thread = null;
          m_throwable = throwable;
          notifyAll();
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/impl/DefaultThreadPool.java
  
  Index: DefaultThreadPool.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.thread.impl;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Executable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.excalibur.threadcontext.ThreadContext;
  import org.apache.excalibur.mpool.ObjectFactory;
  import org.apache.excalibur.mpool.FixedSizePool;
  import org.apache.excalibur.thread.ThreadControl;
  import org.apache.excalibur.thread.ThreadPool;
  
  /**
   * This class is the public frontend for the thread pool code.
   *
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  public class DefaultThreadPool
      extends ThreadGroup
      implements ObjectFactory, LogEnabled, Disposable, ThreadPool
  {
      private FixedSizePool m_pool;
  
      private int m_level;
  
      private Logger m_logger;
  
      private ThreadContext m_context;
  
      public DefaultThreadPool( final int capacity )
          throws Exception
      {
          this( "Worker Pool", capacity );
      }
  
      public DefaultThreadPool( final String name, final int capacity )
          throws Exception
      {
          this( name, capacity, null );
      }
  
      public DefaultThreadPool( final String name,
                                final int capacity,
                                final ThreadContext context )
          throws Exception
      {
          super( name );
          m_pool = new FixedSizePool( this, capacity );
          m_context = context;
      }
  
      public void enableLogging( final Logger logger )
      {
          m_logger = logger;
      }
  
      public void dispose()
      {
          m_pool.dispose();
          m_pool = null;
      }
  
      public Object newInstance()
      {
          final String name = getName() + " Worker #" + m_level++;
  
          ThreadContext context = null;
          if( null != m_context )
          {
              context = m_context.duplicate();
          }
  
          final WorkerThread worker =
              new WorkerThread( this, name, m_pool, context );
          worker.setDaemon( true );
          worker.enableLogging( m_logger );
          worker.start();
          return worker;
      }
  
      public void dispose( final Object object )
      {
          if( object instanceof WorkerThread )
          {
              ((WorkerThread)object).dispose();
          }
      }
  
      public Class getCreatedClass()
      {
          return WorkerThread.class;
      }
  
      /**
       * Run work in separate thread.
       * Return a valid ThreadControl to control work thread.
       *
       * @param work the work to be executed.
       * @return the ThreadControl
       */
      public ThreadControl execute( final Runnable work )
      {
          return execute( new ExecutableRunnable( work ) );
      }
  
      /**
       * Run work in separate thread.
       * Return a valid ThreadControl to control work thread.
       *
       * @param work the work to be executed.
       * @return the ThreadControl
       */
      public ThreadControl execute( final Executable work )
      {
          final WorkerThread worker = getWorker();
          return worker.execute( work );
      }
  
      /**
       * Retrieve a worker thread from pool.
       *
       * @return the worker thread retrieved from pool
       */
      protected WorkerThread getWorker()
      {
          try
          {
              return (WorkerThread)m_pool.acquire();
          }
          catch( final Exception e )
          {
              throw new IllegalStateException( "Unable to access thread pool due to " + e );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/impl/ExecutableRunnable.java
  
  Index: ExecutableRunnable.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.thread.impl;
  
  import org.apache.avalon.framework.activity.Executable;
  
  /**
   * Class to adapt a <code>Runnable</code> object in an <code>Executable</code> object.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  final class ExecutableRunnable
      implements Executable
  {
      ///The runnable instance being wrapped
      private Runnable m_runnable;
  
      /**
       * Create adapter using specified runnable.
       *
       * @param runnable the runnable to adapt to
       */
      protected ExecutableRunnable( final Runnable runnable )
      {
          m_runnable = runnable;
  
          ///Verify runnable is not null
          if( null == runnable )
          {
              throw new NullPointerException( "runnable property is null" );
          }
      }
  
      /**
       * Execute the underlying <code>Runnable</code> object.
       *
       * @throws Exception if an error occurs
       */
      public void execute()
          throws Exception
      {
          m_runnable.run();
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/thread/impl/WorkerThread.java
  
  Index: WorkerThread.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.thread.impl;
  
  import org.apache.excalibur.mpool.Pool;
  import org.apache.excalibur.thread.ThreadControl;
  import org.apache.avalon.framework.activity.Executable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.excalibur.threadcontext.ThreadContext;
  
  /**
   * This class extends the Thread class to add recyclable functionalities.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  class WorkerThread
      extends Thread
      implements LogEnabled
  {
      private Logger m_logger;
      private Pool m_pool;
  
      private Executable m_work;
      private DefaultThreadControl m_threadControl;
      private ThreadContext m_context;
      private boolean m_alive;
  
      private String m_name;
  
      /**
       * Allocates a new <code>Worker</code> object.
       */
      protected WorkerThread( final ThreadGroup group,
                              final String name,
                              final Pool pool,
                              final ThreadContext context )
      {
          super( group, "" );
          m_name = name;
          m_pool = pool;
          m_context = context;
          m_work = null;
          m_alive = true;
  
          setDaemon( false );
      }
  
      public void enableLogging( final Logger logger )
      {
          m_logger = logger;
      }
  
      /**
       * The main execution loop.
       */
      public final synchronized void run()
      {
          debug( "starting." );
  
          // Notify the pool this worker started running.
          //notifyAll();
  
          while( m_alive )
          {
              waitUntilCondition( true );
  
              debug( "running." );
  
              try
              {
                  //TODO: Thread name setting should reuse the ThreadContext code.
                  Thread.currentThread().setName( m_name );
                  if( null != m_context ) ThreadContext.setThreadContext( m_context );
                  m_work.execute();
                  m_threadControl.finish( null );
              }
              catch( final ThreadDeath threadDeath )
              {
                  debug( "thread has died." );
                  m_threadControl.finish( threadDeath );
                  // This is to let the thread death propagate to the runtime
                  // enviroment to let it know it must kill this worker
                  throw threadDeath;
              }
              catch( final Throwable throwable )
              {
                  // Error thrown while working.
                  debug( "error caught: " + throwable );
                  m_threadControl.finish( throwable );
              }
              finally
              {
                  debug( "done." );
                  m_work = null;
                  m_threadControl = null;
                  if( null != m_context ) ThreadContext.setThreadContext( null );
              }
  
              //should this be just notify or notifyAll ???
              //It seems to resource intensive option to use notify()
              //notifyAll();
              notify();
  
              // recycle ourselves
              if( null != m_pool )
              {
                  m_pool.release( this );
              }
              else
              {
                  m_alive = false;
              }
          }
      }
  
      /**
       * Set the <code>alive</code> variable to false causing the worker to die.
       * If the worker is stalled and a timeout generated this call, this method
       * does not change the state of the worker (that must be destroyed in other
       * ways).
       */
      public void dispose()
      {
          debug( "destroying." );
          m_alive = false;
          waitUntilCondition( false );
      }
  
      protected synchronized ThreadControl execute( final Executable work )
      {
          m_work = work;
          m_threadControl = new DefaultThreadControl( this );
  
          debug( "notifying this worker." );
          notify();
  
          return m_threadControl;
      }
  
      /**
       * Set the <code>Work</code> code this <code>Worker</code> must
       * execute and <i>notifies</i> its thread to do it.
       */
      protected synchronized void executeAndWait( final Executable work )
      {
          execute( work );
          waitUntilCondition( false );
      }
  
      private synchronized void waitUntilCondition( final boolean hasWork )
      {
          while( hasWork == ( null == m_work ) )
          {
              try
              {
                  debug( "waiting." );
                  wait();
                  debug( "notified." );
              }
              catch( final InterruptedException ie )
              {
              }
          }
      }
  
      private void debug( final String message )
      {
          if( false )
          {
              final String output = getName() + ": " + message;
              m_logger.debug( output );
              //System.out.println( output );
          }
      }
  }
  
  
  
  1.2       +324 -324  jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/MultiThreadedPoolComparisonProfile.java
  
  Index: MultiThreadedPoolComparisonProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/mpool/test/MultiThreadedPoolComparisonProfile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MultiThreadedPoolComparisonProfile.java	7 Aug 2002 22:44:26 -0000	1.1
  +++ MultiThreadedPoolComparisonProfile.java	8 Aug 2002 00:36:26 -0000	1.2
  @@ -1,324 +1,324 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  -    must not be used to endorse or promote products derived from this  software
  -    without  prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation. For more  information on the
  - Apache Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.excalibur.mpool.test;
  -
  -import org.apache.avalon.excalibur.pool.Poolable;
  -import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
  -import org.apache.avalon.excalibur.testcase.LatchedThreadGroup;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.excalibur.mpool.Pool;
  -
  -/**
  - * This is used to profile and compare various pool implementations
  - *  given a single access thread.
  - *
  - * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  - * @version $Id$
  - */
  -public class MultiThreadedPoolComparisonProfile
  -    extends PoolComparisonProfileAbstract
  -{
  -    protected static final int THREADS = 100;
  -
  -    private int m_startedCount;
  -    private boolean m_latched;
  -    private int m_completedCount;
  -    private int m_getCount;
  -    private Throwable m_throwable;
  -
  -    /*---------------------------------------------------------------
  -     * Constructors
  -     *-------------------------------------------------------------*/
  -    public MultiThreadedPoolComparisonProfile( String name )
  -    {
  -        super( name );
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * PoolComparisonProfileAbstract Methods
  -     *-------------------------------------------------------------*/
  -    protected long getPoolRunTime( final Pool pool, final int gets )
  -        throws Exception
  -    {
  -        if( gets % THREADS != 0 )
  -        {
  -            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  -            fail( "gets must be evenly divisible by THREADS" );
  -        }
  -
  -        m_getCount = 0;
  -        m_throwable = null;
  -
  -        // Create the runnable
  -        MPoolRunner runnable = new MPoolRunner( pool, gets, m_logger );
  -
  -        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  -        group.enableLogging( m_logger );
  -
  -        long duration;
  -        try
  -        {
  -            duration = group.go();
  -        }
  -        catch( Throwable t )
  -        {
  -            // Throwable could have been thrown by one of the tests.
  -            if( m_throwable == null )
  -            {
  -                m_throwable = t;
  -            }
  -            duration = 0;
  -        }
  -
  -        if( m_throwable != null )
  -        {
  -            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  -        }
  -
  -        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  -
  -        // Dispose if necessary
  -        if( pool instanceof Disposable )
  -        {
  -            ( (Disposable)pool ).dispose();
  -        }
  -
  -        return duration;
  -    }
  -
  -    /*---------------------------------------------------------------
  -     * PoolComparisonProfileAbstract Methods
  -     *-------------------------------------------------------------*/
  -    protected long getPoolRunTime( final org.apache.avalon.excalibur.pool.Pool pool, final int gets )
  -        throws Exception
  -    {
  -        if( gets % THREADS != 0 )
  -        {
  -            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  -            fail( "gets must be evenly divisible by THREADS" );
  -        }
  -
  -        m_getCount = 0;
  -        m_throwable = null;
  -
  -        // Create the runnable
  -        PoolRunner runnable = new PoolRunner( pool, gets, m_logger );
  -
  -        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  -        group.enableLogging( m_logger );
  -
  -        long duration;
  -        try
  -        {
  -            duration = group.go();
  -        }
  -        catch( Throwable t )
  -        {
  -            // Throwable could have been thrown by one of the tests.
  -            if( m_throwable == null )
  -            {
  -                m_throwable = t;
  -            }
  -            duration = 0;
  -        }
  -
  -        if( m_throwable != null )
  -        {
  -            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  -        }
  -
  -        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  -
  -        // Dispose if necessary
  -        if( pool instanceof Disposable )
  -        {
  -            ( (Disposable)pool ).dispose();
  -        }
  -
  -        return duration;
  -    }
  -
  -    private static class PoolRunner implements Runnable
  -    {
  -        private Logger m_logger;
  -        private org.apache.avalon.excalibur.pool.Pool m_pool;
  -        private int m_getCount = 0;
  -        private Throwable m_throwable = null;
  -        private int m_gets;
  -
  -        public PoolRunner( org.apache.avalon.excalibur.pool.Pool pool, int gets, Logger logger )
  -        {
  -            m_pool = pool;
  -            m_logger = logger;
  -            m_gets = gets;
  -        }
  -
  -        public int getCount()
  -        {
  -            return m_getCount;
  -        }
  -
  -        public Throwable getThrowable()
  -        {
  -            return m_throwable;
  -        }
  -
  -        public void run()
  -        {
  -            // Perform this threads part of the test.
  -            final int cnt = m_gets / THREADS;
  -            final Poolable[] poolTmp = new Poolable[ cnt ];
  -            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  -            for( int i = 0; i < loops; i++ )
  -            {
  -                // Get some Poolables
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    try
  -                    {
  -                        poolTmp[ j ] = m_pool.get();
  -                        m_getCount++;
  -                    }
  -                    catch( Throwable t )
  -                    {
  -                        m_logger.error( "Unexpected error", t );
  -
  -                        if( m_throwable == null )
  -                        {
  -                            m_throwable = t;
  -                        }
  -
  -                        return;
  -                    }
  -                }
  -
  -                // Make the loops hold the poolables longer than they are released, but only slightly.
  -                Thread.yield();
  -
  -                // Put the Poolables back
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    m_pool.put( poolTmp[ j ] );
  -                    m_getCount--;
  -                    poolTmp[ j ] = null;
  -                }
  -            }
  -        }
  -    }
  -
  -    private static class MPoolRunner implements Runnable
  -    {
  -        private Logger m_logger;
  -        private Pool m_pool;
  -        private int m_getCount = 0;
  -        private Throwable m_throwable = null;
  -        private final int m_gets;
  -
  -        public MPoolRunner( Pool pool, int gets, Logger logger )
  -        {
  -            m_pool = pool;
  -            m_logger = logger;
  -            m_gets = gets;
  -        }
  -
  -        public int getCount()
  -        {
  -            return m_getCount;
  -        }
  -
  -        public Throwable getThrowable()
  -        {
  -            return m_throwable;
  -        }
  -
  -        public void run()
  -        {
  -            // Perform this threads part of the test.
  -            final int cnt = m_gets / THREADS;
  -            final Object[] poolTmp = new Poolable[ cnt ];
  -            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  -            for( int i = 0; i < loops; i++ )
  -            {
  -                // Get some Poolables
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    try
  -                    {
  -                        poolTmp[ j ] = m_pool.acquire();
  -                        m_getCount++;
  -                    }
  -                    catch( Throwable t )
  -                    {
  -                        m_logger.error( "Unexpected error after " + m_getCount +
  -                                        " items retrieved and " + m_gets + " requested", t );
  -
  -                        if( m_throwable == null )
  -                        {
  -                            m_throwable = t;
  -                        }
  -                        return;
  -                    }
  -                }
  -
  -                // Make the loops hold the poolables longer than they are released, but only slightly.
  -                Thread.yield();
  -
  -                // Put the Poolables back
  -                for( int j = 0; j < cnt; j++ )
  -                {
  -                    m_pool.release( poolTmp[ j ] );
  -                    m_getCount--;
  -                    poolTmp[ j ] = null;
  -                }
  -            }
  -        }
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.excalibur.mpool.test;
  +
  +import org.apache.avalon.excalibur.pool.Poolable;
  +import org.apache.avalon.excalibur.testcase.CascadingAssertionFailedError;
  +import org.apache.avalon.excalibur.testcase.LatchedThreadGroup;
  +import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.avalon.framework.logger.Logger;
  +import org.apache.excalibur.mpool.Pool;
  +
  +/**
  + * This is used to profile and compare various pool implementations
  + *  given a single access thread.
  + *
  + * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
  + * @version $Id$
  + */
  +public class MultiThreadedPoolComparisonProfile
  +    extends PoolComparisonProfileAbstract
  +{
  +    protected static final int THREADS = 100;
  +
  +    private int m_startedCount;
  +    private boolean m_latched;
  +    private int m_completedCount;
  +    private int m_getCount;
  +    private Throwable m_throwable;
  +
  +    /*---------------------------------------------------------------
  +     * Constructors
  +     *-------------------------------------------------------------*/
  +    public MultiThreadedPoolComparisonProfile( String name )
  +    {
  +        super( name );
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * PoolComparisonProfileAbstract Methods
  +     *-------------------------------------------------------------*/
  +    protected long getPoolRunTime( final Pool pool, final int gets )
  +        throws Exception
  +    {
  +        if( gets % THREADS != 0 )
  +        {
  +            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  +            fail( "gets must be evenly divisible by THREADS" );
  +        }
  +
  +        m_getCount = 0;
  +        m_throwable = null;
  +
  +        // Create the runnable
  +        MPoolRunner runnable = new MPoolRunner( pool, gets, m_logger );
  +
  +        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  +        group.enableLogging( m_logger );
  +
  +        long duration;
  +        try
  +        {
  +            duration = group.go();
  +        }
  +        catch( Throwable t )
  +        {
  +            // Throwable could have been thrown by one of the tests.
  +            if( m_throwable == null )
  +            {
  +                m_throwable = t;
  +            }
  +            duration = 0;
  +        }
  +
  +        if( m_throwable != null )
  +        {
  +            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  +        }
  +
  +        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  +
  +        // Dispose if necessary
  +        if( pool instanceof Disposable )
  +        {
  +            ( (Disposable)pool ).dispose();
  +        }
  +
  +        return duration;
  +    }
  +
  +    /*---------------------------------------------------------------
  +     * PoolComparisonProfileAbstract Methods
  +     *-------------------------------------------------------------*/
  +    protected long getPoolRunTime( final org.apache.avalon.excalibur.pool.Pool pool, final int gets )
  +        throws Exception
  +    {
  +        if( gets % THREADS != 0 )
  +        {
  +            m_logger.info( "Invalid: " + gets % THREADS + " gets(" + gets + ") threads(" + THREADS + ")" );
  +            fail( "gets must be evenly divisible by THREADS" );
  +        }
  +
  +        m_getCount = 0;
  +        m_throwable = null;
  +
  +        // Create the runnable
  +        PoolRunner runnable = new PoolRunner( pool, gets, m_logger );
  +
  +        LatchedThreadGroup group = new LatchedThreadGroup( runnable, THREADS );
  +        group.enableLogging( m_logger );
  +
  +        long duration;
  +        try
  +        {
  +            duration = group.go();
  +        }
  +        catch( Throwable t )
  +        {
  +            // Throwable could have been thrown by one of the tests.
  +            if( m_throwable == null )
  +            {
  +                m_throwable = t;
  +            }
  +            duration = 0;
  +        }
  +
  +        if( m_throwable != null )
  +        {
  +            throw new CascadingAssertionFailedError( "Exception in test thread.", m_throwable );
  +        }
  +
  +        assertTrue( "m_getCount == 0 (" + m_getCount + ")", m_getCount == 0 );
  +
  +        // Dispose if necessary
  +        if( pool instanceof Disposable )
  +        {
  +            ( (Disposable)pool ).dispose();
  +        }
  +
  +        return duration;
  +    }
  +
  +    private static class PoolRunner implements Runnable
  +    {
  +        private Logger m_logger;
  +        private org.apache.avalon.excalibur.pool.Pool m_pool;
  +        private int m_getCount = 0;
  +        private Throwable m_throwable = null;
  +        private int m_gets;
  +
  +        public PoolRunner( org.apache.avalon.excalibur.pool.Pool pool, int gets, Logger logger )
  +        {
  +            m_pool = pool;
  +            m_logger = logger;
  +            m_gets = gets;
  +        }
  +
  +        public int getCount()
  +        {
  +            return m_getCount;
  +        }
  +
  +        public Throwable getThrowable()
  +        {
  +            return m_throwable;
  +        }
  +
  +        public void run()
  +        {
  +            // Perform this threads part of the test.
  +            final int cnt = m_gets / THREADS;
  +            final Poolable[] poolTmp = new Poolable[ cnt ];
  +            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  +            for( int i = 0; i < loops; i++ )
  +            {
  +                // Get some Poolables
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    try
  +                    {
  +                        poolTmp[ j ] = m_pool.get();
  +                        m_getCount++;
  +                    }
  +                    catch( Throwable t )
  +                    {
  +                        m_logger.error( "Unexpected error", t );
  +
  +                        if( m_throwable == null )
  +                        {
  +                            m_throwable = t;
  +                        }
  +
  +                        return;
  +                    }
  +                }
  +
  +                // Make the loops hold the poolables longer than they are released, but only slightly.
  +                Thread.yield();
  +
  +                // Put the Poolables back
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    m_pool.put( poolTmp[ j ] );
  +                    m_getCount--;
  +                    poolTmp[ j ] = null;
  +                }
  +            }
  +        }
  +    }
  +
  +    private static class MPoolRunner implements Runnable
  +    {
  +        private Logger m_logger;
  +        private Pool m_pool;
  +        private int m_getCount = 0;
  +        private Throwable m_throwable = null;
  +        private final int m_gets;
  +
  +        public MPoolRunner( Pool pool, int gets, Logger logger )
  +        {
  +            m_pool = pool;
  +            m_logger = logger;
  +            m_gets = gets;
  +        }
  +
  +        public int getCount()
  +        {
  +            return m_getCount;
  +        }
  +
  +        public Throwable getThrowable()
  +        {
  +            return m_throwable;
  +        }
  +
  +        public void run()
  +        {
  +            // Perform this threads part of the test.
  +            final int cnt = m_gets / THREADS;
  +            final Object[] poolTmp = new Poolable[ cnt ];
  +            final int loops = ( TEST_SIZE / THREADS ) / cnt;
  +            for( int i = 0; i < loops; i++ )
  +            {
  +                // Get some Poolables
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    try
  +                    {
  +                        poolTmp[ j ] = m_pool.acquire();
  +                        m_getCount++;
  +                    }
  +                    catch( Throwable t )
  +                    {
  +                        m_logger.error( "Unexpected error after " + m_getCount +
  +                                        " items retrieved and " + m_gets + " requested", t );
  +
  +                        if( m_throwable == null )
  +                        {
  +                            m_throwable = t;
  +                        }
  +                        return;
  +                    }
  +                }
  +
  +                // Make the loops hold the poolables longer than they are released, but only slightly.
  +                Thread.yield();
  +
  +                // Put the Poolables back
  +                for( int j = 0; j < cnt; j++ )
  +                {
  +                    m_pool.release( poolTmp[ j ] );
  +                    m_getCount--;
  +                    poolTmp[ j ] = null;
  +                }
  +            }
  +        }
  +    }
  +}
  
  
  
  1.1                  jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/thread/impl/test/DefaultThreadPoolTestCase.java
  
  Index: DefaultThreadPoolTestCase.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.excalibur.thread.impl.test;
  
  import java.util.HashMap;
  import junit.framework.TestCase;
  import org.apache.excalibur.thread.impl.DefaultThreadPool;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  import org.apache.excalibur.threadcontext.ThreadContext;
  import org.apache.excalibur.threadcontext.impl.DefaultThreadContextPolicy;
  
  /**
   * TestCase for DefaultThreadPool.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:colus@apache.org">Eung-ju Park</a>
   */
  public class DefaultThreadPoolTestCase
      extends TestCase
  {
      public DefaultThreadPoolTestCase( final String name )
      {
          super( name );
      }
  
      public void testWithThreadContext()
          throws Exception
      {
          final DefaultThreadContextPolicy policy = new DefaultThreadContextPolicy();
          final HashMap map = new HashMap( 1 );
          map.put( DefaultThreadContextPolicy.CLASSLOADER, getClass().getClassLoader() );
          final ThreadContext threadContext = new ThreadContext( policy, map );
          final DefaultThreadPool pool = new DefaultThreadPool( "default", 10, threadContext );
          pool.setDaemon( false );
          pool.enableLogging( new ConsoleLogger() );
          pool.execute( new DummyRunnable() );
      }
  
      public void testWithoutThreadContext()
          throws Exception
      {
          final ThreadContext threadContext = ThreadContext.getThreadContext();
          final DefaultThreadPool pool = new DefaultThreadPool( "default", 10, threadContext );
          pool.setDaemon( false );
          pool.enableLogging( new ConsoleLogger() );
          pool.execute( new DummyRunnable() );
      }
  
      private static class DummyRunnable
          implements Runnable
      {
          public void run()
          {
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>