3 Replies Latest reply on Dec 27, 2007 3:20 AM by Vicky Kak

    WorkManager thread pooling

    Eli Avzak Newbie

      Hi,
      We are developing a resource adapter which uses threads in order to process incoming network data. These threads are obtained from the WorkManager instance which uses a BasicThreadPool instance as its thread pooling mechanism.
      When we tried to configure the thread pool we noticed that its minimum pool size is always the same as its maximum size. As a result, if the maximum size is configured to, say 500, then its minimum size is also set to 500, so 500 threads will be created even if there are idle threads in the pool (because the pool prefers to first fill the pool up to its min size).
      After threads were allocated and their keep alive time has expired, they are all removed from the pool, although you would expect a minimum size will be kept.
      All of this results in a very inefficient idle threads management.
      Is this issue a known bug? if so, when it is expected to be fixed? is it possible to configure the WorkManager to use other implementation of thread pool?

      Regards,
      Eli Avzak

        • 1. Re: WorkManager thread pooling
          Vicky Kak Master

           

          "avzak" wrote:
          Hi,
          We are developing a resource adapter which uses threads in order to process incoming network data. These threads are obtained from the WorkManager instance which uses a BasicThreadPool instance as its thread pooling mechanism.
          When we tried to configure the thread pool we noticed that its minimum pool size is always the same as its maximum size.

          How/Where did you configure the ThreadPool ?

          "avzak" wrote:

          Is this issue a known bug? if so, when it is expected to be fixed? is it possible to configure the WorkManager to use other implementation of thread pool?
          Regards,
          Eli Avzak

          The JBossWorkManager is configured in $JBOSS_HOME/server/default/deploy/jbossjca-service.xml
          <mbean code="org.jboss.util.threadpool.BasicThreadPool"
           name="jboss.jca:service=WorkManagerThreadPool">
           <!-- The name that appears in thread names -->
           <attribute name="Name">WorkManager</attribute>
           <!-- The maximum amount of work in the queue -->
           <attribute name="MaximumQueueSize">1024</attribute>
           <!-- The maximum number of active threads -->
           <attribute name="MaximumPoolSize">100</attribute>
           <!-- How long to keep threads alive after their last work (default one minute) -->
           <attribute name="KeepAliveTime">60000</attribute>
           </mbean>
          
           <mbean code="org.jboss.resource.work.JBossWorkManager"
           name="jboss.jca:service=WorkManager">
           <depends optional-attribute-name="ThreadPoolName">jboss.jca:service=WorkManagerThreadPool</depends>
           <depends optional-attribute-name="XATerminatorName">jboss:service=TransactionManager</depends>
           </mbean>

          You should be able to plugin custom threadpool implementation here .
          But before doing so make sure that your observation regarding the BasicThreadPool is correct .

          • 2. Re: WorkManager thread pooling
            Eli Avzak Newbie

            Thanks for the quick reply.
            I tried to configure the thread pool in jbossjca-service.xml by adding the
            MinimumPoolSize attribute. I also tried to modify the min/max attributes of the WorkManagerThreadPool MBean through the JMX console. Both results the same: the max size cannot be set to a greater value than the min size.
            Am i missing something here?

            Thanks,
            Eli

            • 3. Re: WorkManager thread pooling
              Vicky Kak Master

               

              "avzak" wrote:

              Am i missing something here?

              No , I looked at the code which displays the Min/Max pool size , here is it
              public int getMinimumPoolSize()
               {
               return executor.getCorePoolSize();
               }
              
               public void setMinimumPoolSize(int size)
               {
               synchronized (executor)
               {
               // Don't let the min size > max size
               if (executor.getMaximumPoolSize() < size)
               {
               executor.setCorePoolSize(size);
               executor.setMaximumPoolSize(size);
               }
               }
               }
              
               public int getMaximumPoolSize()
               {
               return executor.getMaximumPoolSize();
               }
              
               public void setMaximumPoolSize(int size)
               {
               synchronized (executor)
               {
               executor.setCorePoolSize(size);
               executor.setMaximumPoolSize(size);
               }
               }

              http://anonsvn.jboss.org/repos/common/common-core/trunk/src/main/java/org/jboss/util/threadpool/BasicThreadPool.java
              In the above core you will see calling the setMaximumPoolSize() sets executor.setCorePoolSize(size) and the getMinPoolSize() displays the corePoolSize .
              Actaully in setMaximumPoolSize(..) the executor.setCorePoolSize(size); should be set only if the size(max size)<getMinimumPoolSize().

              Even in older version of the ThreadPool I see the similar implementation

              public void setMaximumPoolSize(int size)
               {
               synchronized (executor)
               {
               executor.setMinimumPoolSize(size);
               executor.setMaximumPoolSize(size);
               // Don't let the min size > max size
               if (executor.getKeepAliveSize() > size)
               executor.setKeepAliveSize(size);
               }
               }

              http://anonsvn.jboss.org/repos/common/common-core/tags/2.0.0/src/main/java/org/jboss/util/threadpool/BasicThreadPool.java

              A quicker solution would be to have the custom ThreadPool Implementation which would take care of min/max pool count, you can simply take the jboss code and introduce the check as I have explained earlier .