Custom pool configuration for your EJBs on JBoss AS 7/WildFly

Stateless session beans are held in a pool which can be configured at EJB Container level. You can define as many pool configuration as you want and then decide which one to use for your EJB container.

One thing which if often requested is to apply some specific settings for a particular EJB.

With JBoss AS 7 /EAP 6 and WildFly it is possible to apply some specific pool settings by decorating your class with the @org.jboss.ejb3.annotation.Pool annotation:

import org.jboss.ejb3.annotation.Pool;

@Stateless
@Pool(value="poolcustom") 

public class  ServiceBean   {
. . .
}

 The value for the pool needs to be defined in your server configuration:

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

 Please note that you can also define the Pool size using the jboss-ejb3.xml file as follows:

<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="urn:ejb-pool:1.0" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd
http://www.jboss.org/j2ee/schema/jboss_5_0.xsd" version="3.1" impl-version="2.0">
	<assembly-descriptor>
		<p:pool>
			<ejb-name>ServiceBean</ejb-name>
			<p:bean-instance-pool-ref>poolcustom2</p:bean-instance-pool-ref>
		</p:pool>
 
	</assembly-descriptor>
</jboss:ejb-jar>

 

Found the article helpful? if so please follow us on Socials