Tips for improving EJB performance

Source: Internet
Author: User
Tags jboss

The project is here, and new problems begin to emerge. EJB calls are time-consuming and laborious. How to improve EJB performance? To solve this problem, we began to write and discuss. When it was done, I realized that the techniques we applied were summed up in 10. Summarize these techniques to improve EJB performance and make reference for future projects.

1. Encapsulates multiple entity beans with a session bean, encapsulating the remote calls and local calls of the original multiple entity beans in a session bean. So create a serverfacade that provides a unified interface for obtaining EJB home and fetching objects for multiple objects. Serverfacade provides caching for the home handle of all ejbs to be used by the program, increasing the time to access the Jndi name, and achieving the goal of increased access efficiency. Methods to find Jndi name in the future should be written in the interface and invoked directly from the interface.

2. A coarse-grained method is not recommended for use in the remote interface of EJBS.

3. If the remote interface of the EJB succeeds, the remote interface should no longer be used, but the remote interface is constructed into a generic Java object to reduce access to the network by invoking a generic Java object.

4. If you deploy the EJB client and EJB on the same JVM, build a local interface that uses the EJB2.0 specification instead of the remote interface.

5. Use the "transient" keyword to declare unnecessary data variables, instead of the previous "public", "private" and so on, to avoid unnecessary data variables to occupy network resources. Example:

public class DemoCMP implements EntityBean {
transient EntityContext entCtx;
transient InitialContext initCtx;
public String id;
public String description;

}

6. In the Ejb-jar.xml deployment file, assign the Trans-attribute property to "notsupported" or "Never" to the transaction-only method of the session bean

<ejb-jar>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>abookesessionBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

7. Set the timeout for the transaction, in JBoss, to modify the ${jboss.home}/server/${jboss.configuration}/conf/jboss-service.xml, as follows:

<server>

<mbean code="org.jboss.tm.TransactionManagerService"
name="jboss:service=TransactionManager">
<attribute name="TransactionTimeout">300</attribute>
</mbean>

</server>

8. When a transaction locks the row records of a database, the transaction should span the smallest possible time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.