Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

21.2. Configuring Bean Pools

21.2.1. Bean Pools

JBoss EAP 6 maintains a number of instances of deployed stateless enterprise beans in memory to provide faster performance. This technique is called bean pooling. When a bean is required the application server can take one from the appropriate pool of already available beans instead of instantiating a new one. When the bean is no longer required it is returned to the pool for reuse.
Bean pools are configured and maintained separately for stateless session beans and for message-driven beans.
@org.jboss.ejb3.annotation.Pool annotation can be used on EJBs to identify the pool, which has to be used for that EJB. This annotation points to the name of that pool.

21.2.2. Create a Bean Pool

Bean pools can be created using the Management Console and the CLI tool.
Bean pools can also be created by adding the required bean pool configuration to the server configuration file using a text editor. Example 21.2, “XML Configuration Sample” is an example of what this configuration looks like.

Procedure 21.1. Create a bean pool using the Management Console

  1. Login to the Management Console. Refer to Section 3.3.2, “Log in to the Management Console”.
  2. Click on the Configuration tab at the top of the screen. Expand the Container menu and select EJB 3. Select the Bean Pools tab.
  3. Click Add. The Add EJB3 Bean Pools dialog appears.
  4. Specify the required details, Name, Max Pool Size, Timeout value, and Timeout unit.
  5. Click Save button to finish.

Procedure 21.2. Create a bean pool using the CLI

  1. Launch the CLI tool and connect to your server. Refer to Section 3.4.4, “Connect to a Managed Server Instance Using the Management CLI”.
  2. Use the add operation with the following syntax.
    /subsystem=ejb3/strict-max-bean-instance-pool=BEANPOOLNAME:add(max-pool-size=MAXSIZE, timeout=TIMEOUT, timeout-unit="UNIT")
    • Replace BEANPOOLNAME with the required name for the bean pool.
    • Replace MAXSIZE with the maximum size of the bean pool.
    • Replace TIMEOUT
    • Replace UNIT with the required time unit. Allowed values are: NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, and DAYS.
  3. Use the read-resource operation to confirm the creation of the bean pool.
    /subsystem=ejb3/strict-max-bean-instance-pool=BEANPOOLNAME:read-resource

Example 21.1. Create a Bean Pool using the CLI

[standalone@localhost:9999 /] /subsystem=ejb3/strict-max-bean-instance-pool=ACCTS_BEAN_POOL:add(max-pool-size=500, timeout=5000, timeout-unit="SECONDS")  
{"outcome" => "success"}

Example 21.2. XML Configuration Sample

<subsystem xmlns="urn:jboss:domain:ejb3:1.2">

   <pools>

      <bean-instance-pools>

         <strict-max-pool  name="slsb-strict-max-pool" max-pool-size="20" 
            instance-acquisition-timeout="5" 
            instance-acquisition-timeout-unit="MINUTES" />

         <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" 
            instance-acquisition-timeout="5" 
            instance-acquisition-timeout-unit="MINUTES" />

      </bean-instance-pools>

   </pools>

</subsystem>

21.2.3. Remove a Bean Pool

Unused bean pools can be removed using the Management Console.

Prerequisites:

Procedure 21.3. Remove a bean pool using the Management Console

  1. Login to the Management Console. Refer to Section 3.3.2, “Log in to the Management Console”.
  2. Click on the Configuration tab at the top of the screen. Expand the Container menu and select EJB 3. Select the Bean Pools tab.
  3. Select the bean pool to remove in the list.
  4. Click Remove. The Remove Item dialog appears.
  5. Click Confirm to confirm.

Procedure 21.4. Remove a bean pool using the CLI

  1. Launch the CLI tool and connect to your server. Refer to Section 3.4.4, “Connect to a Managed Server Instance Using the Management CLI”.
  2. Use the remove operation with the following syntax.
    /subsystem=ejb3/strict-max-bean-instance-pool=BEANPOOLNAME:remove
    • Replace BEANPOOLNAME with the required name for the bean pool.

Example 21.3. Removing a Bean Pool using the CLI

[standalone@localhost:9999 /] /subsystem=ejb3/strict-max-bean-instance-pool=ACCTS_BEAN_POOL:remove  
{"outcome" => "success"}

21.2.4. Edit a Bean Pool

Bean pools can be edited using the Management Console.

Procedure 21.5. Edit a bean pool using the Management Console

  1. Click on the Configuration tab at the top of the screen. Expand the Container menu and select EJB 3. Select the Bean Pools tab.
  2. Select the bean pool you want to edit.
  3. Click Edit.
  4. Edit the details you want to change. Only Max Pool Size, Timeout value, and Timeout Unit can be changed.
  5. Click Save to finish.

Procedure 21.6. Edit a bean pool using the CLI

  1. Launch the CLI tool and connect to your server. Refer to Section 3.4.4, “Connect to a Managed Server Instance Using the Management CLI”.
  2. Use the write-attribute operation with the following syntax for each attribute of the bean pool to be changed.
    /subsystem=ejb3/strict-max-bean-instance-pool=BEANPOOLNAME:write-attribute(name="ATTRIBUTE", value="VALUE")
    • Replace BEANPOOLNAME with the required name for the bean pool.
    • Replace ATTRIBUTE with the name of the attribute to be edited. The attributes that can be edited in this way are max-pool-size, timeout, and timeout-unit.
    • Replace VALUE with the required value of the attribute.
  3. Use the read-resource operation to confirm the changes to the bean pool.
    /subsystem=ejb3/strict-max-bean-instance-pool=BEANPOOLNAME:read-resource

Example 21.4. Set the Timeout Value of a Bean Pool using the CLI

[standalone@localhost:9999 /] /subsystem=ejb3/strict-max-bean-instance-pool=HSBeanPool:write-attribute(name="timeout", value="1500")
{"outcome" => "success"}

21.2.5. Assign Bean Pools for Session and Message-Driven Beans

JBoss Administrators can assign individual bean pools for use by session beans and message-driven beans. Bean pools can be assigned by using the Management Console or the Management CLI.
By default, two bean pools are provided, slsb-strict-max-pool and mdb-strict-max-pool for stateless session beans and message-driven beans respectively.
Additionally, the @Pool annotation can be used on EJBs to identify the pool to be used for that EJB.

Note

Using the @Pool annotation on a particular EJB will override any default settings specified using the management interfaces.

Procedure 21.7. Assign Bean Pools for Session and Message-Driven Beans using the Management Console

  1. Click on the Configuration tab at the top of the screen. Expand the Container menu and select EJB 3. Select the Container tab.
  2. Click Edit.
  3. Select the bean pool to use for each type of bean from the appropriate combo-box.
  4. Click Save to finish.

Procedure 21.8. Assign Bean Pools for Session and Message-Driven Beans using the CLI

  1. Launch the CLI tool and connect to your server. Refer to Section 3.4.4, “Connect to a Managed Server Instance Using the Management CLI”.
  2. Use the write-attribute operation with the following syntax.
    /subsystem=ejb3:write-attribute(name="BEANTYPE", value="BEANPOOL")
    • Replace BEANTYPE with default-mdb-instance-pool for Message-Driven Beans or default-slsb-instance-pool for stateless session beans.
    • Replace BEANPOOL with the name of the bean pool to assign.
  3. Use the read-resource operation to confirm the changes.
    /subsystem=ejb3:read-resource

Example 21.5. Assign a Bean Pool for Session Beans using the CLI

[standalone@localhost:9999 /] /subsystem=ejb3:write-attribute(name="default-slsb-instance-pool", value="LV_SLSB_POOL")  
{"outcome" => "success"}

Example 21.6. XML Configuration Sample

<subsystem xmlns="urn:jboss:domain:ejb3:1.2">
   <session-bean>
      <stateless>
         <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>
      </stateless>
      <stateful default-access-timeout="5000" cache-ref="simple"/>
      <singleton default-access-timeout="5000"/>
   </session-bean>
   <mdb>
      <resource-adapter-ref resource-adapter-name="hornetq-ra"/>
      <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
   </mdb>
</subsystem>

Procedure 21.9. Assign a Bean Pool for a Session or Message-Driven Bean using the @Pool annotation

  1. Add the @Pool annotation to the bean and specify the name of the bean pool to be used.
    @Stateless
    @Pool("slsb-strict-max-pool")
    public class HelloBean implements HelloBeanRemote {
    This will override any default settings created in the management interfaces.
  2. The @org.jboss.ejb3.annotation.Pool annotation is part of the JBoss EJB3 External API and must be added as a dependency. If you are using Maven, the following dependency should be added to your pom.xml file:
    <dependency>
      <groupId>org.jboss.ejb3</groupId>
      <artifactId>jboss-ejb3-ext-api</artifactId>
      <version>2.1.0</version>
    </dependency>