Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
OC4J provides EJB pooling attributes that you can configure to improve performance by reducing the frequency of bean instance creation.
This section describes the following:
You can set the minimum and maximum number of the bean instance pool for session beans, entities, and message-driven beans.
You can configure the bean pool size as follows:
Configuration in the deployment XML overrides the corresponding configuration made using annotations.
You can specify bean instance pool size for EJB 3.0 session and message-driven beans using the following OC4J-proprietary annotations and their attributes:
@StatelessDeployment
attributes:
For more information about these attributes, see Table A-1.
@StatefulDeployment
attributes:
For more information about these attributes, see Table A-1.
@MessageDrivenDeployment
attributes:
For more information about these attributes, see Table A-3.
Example 31-3 shows how to configure these attributes for an EJB 3.0 stateless session bean using the @StatelessDeployment
annotation.
Example 31-3 @StatelessDeployment poolCacheTimeout Attribute
import javax.ejb.Stateless; import oracle.j2ee.ejb.StatelessDeployment; @Stateless @StatelessDeployment( maxInstances=10, minInstances=3 ) public class HelloWorldBean implements HelloWorld { public void sayHello(String name) { System.out.println("Hello "+name +" from first EJB3.0"); } }
You can specify bean instance pool size for EJB 3.0 session and message-driven beans using the following orion-ejb-jar.xml
file elements and their attributes:
<session-deployment>
attributes for stateless session beans:
For more information about these attributes, see Table A-1.
<session-deployment>
attributes for stateful session beans:
For more information about these attributes, see Table A-1.
<message-driven-deployment>
attributes for message-driven beans:
For more information about these attributes, see Table A-3.
Example 31-4 shows how to configure these attributes for an EJB 3.0 stateless session bean using the orion-ejb-jar.xml
file.
Example 31-4 orion-ejb-jar.xml for Bean Instance Pool Size for a Stateless Session Bean
<?xml version="1.0" encoding="utf-8"?> <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" deployment-version="10.1.3.1.0" deployment-time="10b1fb5cdd0" schema-major-version="10" schema-minor-version="0" > <enterprise-beans> <session-deployment max-instances="10" min-instances="3" ... > </session-deployment> ... </enterprise-beans> ... </orion-ejb-jar>
If you change this property using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to modify this parameter dynamically without restarting OC4J (see "Using Oracle Enterprise Manager 10g Application Server Control").
You can set the maximum amount of time that session beans are cached in the bean instance pool.
You can configure pool timeouts for session beans as follows:
Configuration in the deployment XML overrides the corresponding configuration made using annotations.
Example 31-5 shows how to configure the bean instance pool timeout for an EJB 3.0 stateless session bean using the @StatelessDeployment
annotation poolCacheTimeout
attribute.
For more information on this @StatelessDeployment
attribute, see Table A-1. For more information on the @StatelessDeployment
annotation, see "Configuring OC4J-Proprietary Deployment Options on an EJB 3.0 Session Bean".
Example 31-5 @StatelessDeployment poolCacheTimeout Attribute
import javax.ejb.Stateless; import oracle.j2ee.ejb.StatelessDeployment; @Stateless @StatelessDeployment( poolCacheTimeout=90 ) public class HelloWorldBean implements HelloWorld { public void sayHello(String name) { System.out.println("Hello "+name +" from first EJB3.0"); } }
Example 31-6 shows how to configure the bean instance pool timeout for an EJB 3.0 stateful session bean using the @StatefulDeployment
annotation timeout
attribute.
For more information on this @StatelessDeployment
attribute, see Table A-1. For more information on the @StatelessDeployment
annotation, see "Configuring OC4J-Proprietary Deployment Options on an EJB 3.0 Session Bean".
In the orion-ejb-jar.xml
file you set the bean pool timeout with the following attributes of the <session-deployment>
element for session beans:
The pool-cache-timeout
attribute is applicable to stateless session beans and sets how long to keep stateless sessions cached in the pool. The default is 0 seconds, which means never timeout.
For example, if you wanted to set the pool-cache-timeout
to 90 seconds, you would do as follows:
<session-deployment ... pool-cache-timeout="90" ... </session-deployment>
The timeout
attribute is applicable to stateful session beans and sets how long a stateful session bean can remain inactive before it is removed from the bean instance pool. The default is 1800 seconds.
For example, if you wanted to set the stateful session bean inactivity timeout to 900 seconds, you would do as follows:
<session-deployment ... timeout="900" ... </session-deployment>
If you change this property using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to modify this parameter dynamically without restarting OC4J (see "Using Oracle Enterprise Manager 10g Application Server Control").
You can set the maximum amount of time that entities are cached in the bean instance pool.
You can configure pool timeouts for entities as follows:
In the orion-ejb-jar.xml
file you set the bean pool timeout with the following attributes of the <entity-deployment>
element for entities:
The pool-cache-timeout
attribute sets how long entity bean implementation instances are to be kept in the "pooled" (unassigned) state. The default is 60 seconds. Setting this attribute to never
means never timeout.
For example, if you wanted to set the pool-cache-timeout
for entities to 90 seconds, you would do as follows:
<entity-deployment ... pool-cache-timeout="90" ... </entity-deployment>
If you change this property using this method, you must restart OC4J to apply your changes. Alternatively, you can use Application Server Control Console to modify this parameter dynamically without restarting OC4J (see "Using Oracle Enterprise Manager 10g Application Server Control").