4 Replies Latest reply on Jan 25, 2010 2:56 PM by jesper.pedersen

    JBJCA-260: New WorkManager

    jesper.pedersen

      Currently the WorkManager uses the thread pool implementation in JBoss Common. The JBoss Threads project creates a way to define thread pools and their execution parameters to a higher degree.

       

      The new WorkManager implementation should make use of JBoss Threads in order to

       

      1. Provide greater flexibility for thread pool creation
      2. Better alignment thread pools in the JBoss Application Server

       

      We need to define datastructures such that the WorkManager API:

       

      http://java.sun.com/javaee/6/docs/api/javax/resource/spi/work/WorkManager.html

       

      can be implemented.

       

      The WorkManager should reference two thread pools at first:

       

      1. Short running tasks (default)
      2. Long running tasks (tasks with HintsContext.LONGRUNNING_HINT set)

       

      Later we can add support for additional thread pools with custom JBoss hints - such as LOWPRIORITY_HINT and HIGHPRIORITY_HINT.

        • 1. Re: JBJCA-260: New WorkManager
          dmlloyd

          jesper.pedersen wrote:

          [..]
          We need to define datastructures such that the WorkManager API:

           

          http://java.sun.com/javaee/6/docs/api/javax/resource/spi/work/WorkManager.html

           

          can be implemented.

           

          The WorkManager should reference two thread pools at first:

           

          1. Short running tasks (default)
          2. Long running tasks (tasks with HintsContext.LONGRUNNING_HINT set)

           

          Later we can add support for additional thread pools with custom JBoss hints - such as LOWPRIORITY_HINT and HIGHPRIORITY_HINT.

           

          Sounds good.  In order to implement WorkManager, you need to be able to execute tasks in three different ways:

          1. Block the calling thread until the work is complete (with an optional task submission timeout and callbacks)
          2. Block the calling thread until the work is accepted (with an optional task submission timeout and callbacks)
          3. Do not block the calling thread (with an optional task submission timeout and callbacks)

           

          In addition, the callbacks which must be supported include:

          1. Work accepted (i.e. the executor queued the task)
          2. Work started (i.e. a thread began executing the task)
          3. Work completed (i.e. the runnable finished, with or without an exception)
          4. Work rejected (i.e. the executor could not accept the task, or the submission timeout expired before the task started)

           

          I just committed a new version of JBoss Threads into trunk (2.0.0.CR2) which includes a new type, BlockingExecutor, which includes these methods:

          package org.jboss.threads;
          
          public interface BlockingExecutor extends Executor {
              // [...]
              void executeBlocking(Runnable task) throws RejectedExecutionException, InterruptedException;
          
              void executeBlocking(Runnable task, long timeout, TimeUnit unit) throws RejectedExecutionException, InterruptedException;
          
              void executeNonBlocking(Runnable task) throws RejectedExecutionException;
              // [...]
          }
          

           

          All JBoss Threads executors now implement this interface.  With this new executor interface, along with simple wrapper Runnables, all the above requirements should be easily implemented.  Unfortunately this means that the JCA implementation will need a hard dependency on jboss-threads, because there is no java.util.concurrent equivalent to these methods.

          • 2. Re: JBJCA-260: New WorkManager
            jeff.zhang

            Hi David,

             

            JBoss-thread will implement kinds of thread model and JBossAS is using it. I can think it is componet relacing old thread classes in common project. Is that correct?

            • 3. Re: JBJCA-260: New WorkManager
              dmlloyd

              jeff.zhang wrote:

               

              Hi David,

               

              JBoss-thread will implement kinds of thread model and JBossAS is using it. I can think it is componet relacing old thread classes in common project. Is that correct?

               

              Yes, that is correct.  It is a re-imagination of our thread pools based on the java.util.concurrent.Executor model, which did not exist when the original threading code was written.

              • 4. Re: JBJCA-260: New WorkManager
                jesper.pedersen

                Thanks for the update, David.

                 

                I don't see having a direct dependency on JBoss Threads for this project as a problem. So I'll go ahead and use 2.0.0.CR2's BlockingExecutor interface.