JBoss.org Community Documentation

11.4.6.5. Instance Per Transaction Policy

The Instance Per Transaction policy is an advanced configuration that can totally wipe away deadlock and throughput problems caused by JBoss's default locking policy. The default Entity Bean locking policy is to only allow one active instance of a bean. The Instance Per Transaction policy breaks this requirement by allocating a new instance of a bean per transaction and dropping this instance at the end of the transaction. Because each transaction has its own copy of the bean, there is no need for transaction based locking.

This option does sound great but does have some drawbacks right now. First, the transactional isolation behavior of this option is equivalent to READ_COMMITTED. This can create repeatable reads when they are not desired. In other words, a transaction could have a copy of a stale bean. Second, this configuration option currently requires commit-option B or C which can be a performance drain since an ejbLoad must happen at the beginning of the transaction. But, if your application currently requires commit-option B or C anyways, then this is the way to go. The JBoss developers are currently exploring ways to allow commit-option A as well (which would allow the use of caching for this option).

JBoss has container configurations named Instance Per Transaction CMP 2.x EntityBean and Instance Per Transaction BMP EntityBean defined in the standardjboss.xml that implement this locking policy. To use this configuration, you just have to reference the name of the container configuration to use with your bean in the jboss.xml deployment descriptor as show below.

<jboss>
						<enterprise-beans>
						<entity>
						<ejb-name>MyCMP2Bean</ejb-name>
						<jndi-name>MyCMP2</jndi-name>
						<configuration-name>
						Instance Per Transaction CMP 2.x EntityBean
						</configuration-name>
						</entity>
						<entity>
						<ejb-name>MyBMPBean</ejb-name>
						<jndi-name>MyBMP</jndi-name>
						<configuration-name>
						Instance Per Transaction BMP EntityBean
						</configuration-name>
						</entity>
						</enterprise-beans>
						</jboss>
					

Example 11.13. An example of using the Instance Per Transaction policy.