6 Replies Latest reply on Mar 6, 2013 4:33 PM by marched

    Specifying a different WorkManager for a custom resource ada

      Hi,

      I'm using jboss 4.2.3 and I have developed a custom resource adapter. I want my resource adapter to use a different WorkManager than the default jca one "jboss.jca:service=WorkManager" so that threading in this RA is independent and does not interfere with threading in other deployed resource adapters.

      Is there any way of doing this? May I have to deploy another instance of a RARDeployer with another WorkManager and associate it to my resource adapter?

      Thanks a lot!

        • 1. Re: Specifying a different WorkManager for a custom resource
          vickyk

           

          "bortx" wrote:
          I want my resource adapter to use a different WorkManager than the default jca one "jboss.jca:service=WorkManager" so that threading in this RA is independent and does not interfere with threading in other deployed resource adapters.

          Can't do it with JBoss4.x, there is an JIRA for it which I am not able to find now.
          Logically the specific workmanager implementation should be put in the jboss-ra.xml, this file is not there in Jboss4.x
          I think getting it done in JBoss5 should be possible.
          "bortx" wrote:

          Is there any way of doing this? May I have to deploy another instance of a RARDeployer with another WorkManager and associate it to my resource adapter?
          Thanks a lot!

          I don't think this would be possible and easy !


          • 2. Re: Specifying a different WorkManager for a custom resource

            I have developed a work around on this issue and I want your opinion about it. It consist on the following.

            1.- Deploy a service called custom-work-manager-service.xml defining a custom WorkManager with a custom thread pool with the following content

            <server>
            
             <mbean code="org.jboss.util.threadpool.BasicThreadPool"
             name="custom.jca:service=CustomWorkManagerThreadPool">
             <!-- The name that appears in thread names -->
             <attribute name="Name">CustomWorkManager</attribute>
             <!-- The maximum amount of work in the queue -->
             <attribute name="MaximumQueueSize">10</attribute>
             <!-- The maximum number of active threads -->
             <attribute name="MinimumPoolSize">1</attribute>
             <!-- The maximum number of active threads -->
             <attribute name="MaximumPoolSize">10</attribute>
             <!-- How long to keep threads alive after their last work (default one minute) -->
             <attribute name="KeepAliveTime">60000</attribute>
             <!-- The behaviour when the queue is full -> the calling thread blocks until the queue has room -->
             <attribute name="BlockingMode">wait</attribute>
             </mbean>
            
             <mbean code="org.jboss.resource.work.JBossWorkManager"
             name="custom.jca:service=CustomWorkManager">
             <depends optional-attribute-name="ThreadPoolName">custom.jca:service=CustomWorkManagerThreadPool</depends>
             <depends optional-attribute-name="XATerminatorName">jboss:service=TransactionManager</depends>
             </mbean>
            
            </server>



            2.- Accesing this work manager from my resource adapter and using it to submit works instead of the one that is provided by jboss in the BootstrapContext:

            WorkManager customWorkManager = null;
             try {
             MBeanServer server = MBeanServerLocator.locateJBoss();
             customWorkManager = (WorkManager) server.getAttribute(new ObjectName(
             "custom.jca:service=CustomWorkManager"), "Instance");
             } catch (MalformedObjectNameException e) {
             // TODO
             } catch (Exception e) {
             // TODO
             }


            What do you think about it?

            • 3. Re: Specifying a different WorkManager for a custom resource
              vickyk

               

              "bortx" wrote:

              2.- Accesing this work manager from my resource adapter and using it to submit works instead of the one that is provided by jboss in the BootstrapContext:

              Looks good as long as you are not relying on getting the WorkManger by javax.resource.spi.BootstrapContext::getWorkManager()
              btw, did you got a chance to test these configuration changes?

              • 4. Re: Specifying a different WorkManager for a custom resource

                Yeah, I've already tested my resource adapter with this configuration and it works successfully. I want only to know if this approach could have any undesirable impact in the application server.

                For example, does this thread pool definition take threads from any underlying system thread pool, so that it could reduce available threads for other tasks on the server, otherwise, it creates a totally independent (but managed) thread pool?

                • 5. Re: Specifying a different WorkManager for a custom resource ada
                  balaswd

                  Please find the below link : http://java-explorer.blogspot.in/2012/02/workmanager-in-jboss-510.html .. It worked in jboss 5.1.0

                  • 6. Re: Specifying a different WorkManager for a custom resource ada
                    marched

                    Here is how I impemented it with JBoss 5.1.0 :

                     

                    1- Deploy a custom-jboss-beans.xml file :

                     

                    <deployment xmlns="urn:jboss:bean-deployer:2.0">

                     

                       <bean name="CustomWorkManagerThreadPool" class="org.jboss.util.threadpool.BasicThreadPool">
                          <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="custom:service=CustomWorkManagerThreadPool", exposedInterface=org.jboss.util.threadpool.BasicThreadPoolMBean.class)</annotation>
                          <property name="name">CustomWorkManager</property>
                          <property name="maximumQueueSize">100</property>
                          <property name="maximumPoolSize">10</property>
                          <property name="keepAliveTime">60000</property>
                       </bean>

                       <bean name="CustomWorkManager" class="org.jboss.resource.work.JBossWorkManager">
                          <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="sdr:service=CustomWorkManager", exposedInterface=org.jboss.resource.work.JBossWorkManagerMBean.class)</annotation>
                          <property name="threadPool"><inject bean="CustomWorkManagerThreadPool"/></property>
                          <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
                      </bean>

                     

                    </deployment>

                     

                    2 - Use it in code (exception handling omitted) :

                     

                    MBeanServer server = MBeanServerLocator.locateJBoss();
                    WorkManager wm = (WorkManager) server.getAttribute(new ObjectName("custom:service=CustomWorkManager"), "Instance");
                    wm.startWork(aWork);