10 tips for building high performance J2EE applications

xiaoxiao2021-03-06  55

Constructing high performance J2EE applications not only need to understand commonly used implementation skills. Here is the most commonly used 10 effective methods to help architect designers have quickly become this expert.

Java Performance Foundation ---- Memory Management

Any Java application, stand-alone or J2EE's performance foundation can be attributed to how your application manages memory issues. Java's memory management includes two important tasks: memory allocation and memory recycling. In memory allocation, the goal is to reduce the object you need to create. Memory recycling is a universal reason for performance degradation. That is, the more objects in memory, the more difficult garbage recovery. So our attitude towards the creation of objects should be more conservative.

The problem related to the two memory common in J2EE applications is: free objects (also known as memory disclosure) and object cycles (refer to a large number of frequent creation and deletion - reflecting in Java to release reference-object).

We should take care of ensuring that all reachable objects are actually live, that is, these objects are not only in memory, but also exist in the executed code. When the object is already in the application, we have forgotten the free object when deleting the reference to the object.

We know that garbage collection will take up the CPU time. A large number of short-term objects has increased the frequency of garbage recovery.

Do not implement business logic in servlet

When building J2EE applications, architecture engineers usually use the basic part of J2EE, servlet.

If architect does not use Session Beans, Entity Beans, or Message Beans, the improved performance method is very small. Can only be used to increase CPU or more physical servers. EJB uses a cache and resource pool and other methods to improve performance and scalability.

Use local interface to access EJB as much as possible

In the early J2EE (Follow the EJB1.x Specification) application, accessing EJB is `to implement using the remote interface via RMI. With the emergence of EJB2.0, the EJB can be accessed through the local interface, and the RMI is no longer used, and it has been used in the same JVM. But now there are some applications that use EJB1.x and some EJB newers who don't know the use of local interfaces. To illustrate this, we make a comparison: 1. Client application calls local stub2, the Stub assembly parameter 3, the Stub is transmitted to Skeleton4, the Skeleton Decomposing parameter 5, the Skeleton calls EJB object 6, EJB object Execute a container service 7 , EJB object call Enterprise Bean instance 8, enterprise BEA execution operation 9, perform assembly / decomposition steps and return

Compared to remote interface processing, the EJB method for local interfaces is: 1. Client calling local object 2. Local object Executes Container Services 3. Local Object call Enterprise Bean Instance 4. Enterprise Bean instance execution operation 5. No other return steps! !

If you don't need to access a special EJB from a remote client, you should use your local method.

Access to entity EJB in the service of session bean

Accessing entity EJB from servlet is not only low efficiency and is difficult to maintain. Using the Session Facade mode, access packages to entity EJB can be encapsulated in session EJB, and excessive remote calls are avoided in this session EJB.

This technique will have additional performance and extension benefits because session and entity EJB can be improved using cache and resource pool technology. In addition, due to the need for load, sessions and entity EJBs can be extended to other hardware devices, which is more simple than extending the servlet layer to other hardware devices.

Try to access the remote EJB as much as possible

When accessing remote EJB, calling the SET / GET method will generate too much network request, and also causing overload of remote interface processing. To avoid this, consider setting the data attribute in an object so that all data can be passed through the call to the remote EJB. This technology is the Data Transfer Object mode. Optimize SQL

J2EE's architecture design engineers and developers are often not SQL experts or experienced database administrators. First, you should ensure that SQL uses index support provided by the database. In some cases, separate the index and data of the database will increase performance. But you want to know that adding additional indexes can increase SELECT performance but will also reduce the performance of INSERT. For some databases, the order between association tables will seriously affect performance. You can consult a multi-directional database administrator.

Avoid excessive SQL in the entity EJB

Sometimes, multiple SQL statements are executed through the entity EJB access data. According to J2EE specification, the first step will call the entity bean's Find (discovery) method; in the second step, the container will call ejbload () from the database when the business method of the entity EJB is called.

Many CMP (Container Management Persistence) Caches entity data when calling the discovery method, so no longer accesses the database when calling ejbload (). You should avoid using BMP (Persistence of bean management) or to achieve a cache algorithm to avoid secondary access databases.

Access read-only data using the Fast Lane Reader mode

J2EE applications often have access to a large amount of long-term data in a read-only way, rather than accessing a single entity, such as browsing the online product catalog. Under this only case, the use of entity EJB access data will cause serious overload and is very troublesome. The entity EJB is suitable for coarse granular access to a single entity, and accesses a large number of lists read-only data is not high. Whether using CMP or BMP, you must write code to operate multiple entities EJBs and their associations. This will result in accessing multiple databases and there is a lot of unnecessary transaction overhead.

Use Java Messaging Servce (Message Service)

The J2EE specification provides built-in asynchronous processing services in JMS. When it comes to system requirements, it should be understood that the JMS should be used to design asynchronous processing. Once you are determined to perform some asynchronous processing, then the task of synchronization should be, the better, and the database-intensive operation is scheduled to be completed in later asynchronous processing.

Cache JNDI LOOKUP lookup

Many operations consume a lot of resources when performing JNDI lookup. The JNDI resource should usually be cached to avoid network calls and some processing overloads. Can cached JNDI findings include: EJB Home InterfacesData Sourceesjms Connection FactoryMs destinations / Topics

Some JNDI packages achieve cache functions. However, this function is limited when the Narrow method of the EJB main interface is called.

The design of the cache lookup should use the shared intialContext instance, although it is troublesome. This is because you need to access multiple data sources, including the parameters of the application resource file jndi.properties, system properties, and pass to the parameters of the constructor.

转载请注明原文地址:https://www.9cbs.com/read-115362.html

New Post(0)