Address: http://blog.csdn.net/jinhuiyu/archive/2008/12/10/3487588.aspx
Many application presentation layers use JSP and Servlet. This article discusses how to improve the performance of such applications through Coding best practices and deployment process configuration.
Recommended best coding practices
This section provides some tips and coding practices to improve the performance of JSP and servlet. Here are some general rules for improving the performance of JSP and servlet.
- Minimize java synchronization in servlet.
- Do not use the single-threaded servlet mode.
- Use the servlet init () method to perform some expensive one-time initialization.
- Avoid using System. out. pintln.
Avoid using shared and modifiable class variables
In the multi-threaded servlet mode (by default), an application server instance has only one servlet instance, and all requests of this servlet share the same
Servlet instances, if there is a synchronous code block in the servlet, it will cause thread competition, because the servlet class variable creation needs to be synchronized, so avoid using shared modifiable classes
Variable.
HTTP Session Processing
When using HTTP Session, follow these rules:
- Do not create a Session at will. Session creation is not free. Do not create
- If the session is not required, use javax. servlet. http. HttpSession. invalidate () to release the session.
- Ensuring session miniaturization can reduce the response time. If possible, ensure that the session is smaller than 7 kb.
- Use the <% page session = "false" %> command in JSP to prevent the Application Server from automatically creating a session when it is not needed.
- Avoid storing enlarged objects in the session, which will force serialization and increase excessive computing. Normally, do not store enlarged objects in the session.
- Do not cache transaction data into HttpSession. accessing the data in HttpSession is non-transactional. It is best to store the data in the database or entity.
If the transaction fails, it will return to its original state. However, the invalid or inaccurate data will continue to be stored in the session. The Application Server provides read-only beans.
The manager caches the read-only data.
Configuration and deployment skills
Follow these configuration skills to improve performance. These skills are used in the product environment, not the development environment.
- To increase the loading time of classes, avoid using too many directories in the CLASSPATH of the server, and issue the classes related to the application to the jar file.
- The HTTP response time is closely related to the adjustment of the HTTP server.
- If possible, cache the servlet results.
- If an application does not contain any JEB, deploy the application as a war file instead of an ear file.
SSL Optimization
Only talk about Solaris.
Disable Security Manager (for Appliciation Server)
Security
Manager is very expensive, because the doPrivileged () method must be called when the required resources are called, and
Resources. If you are sure that your server has no malicious code and you do not use user authentication, you can disable secrity manager.
To disable the server. policy file, go to the Admin Console. In ations> config-name> JVM Setting, and delete the options that contain text.
-Djava. security. manager
I have never translated so many things. I'm so tired. Let's continue tomorrow. EJB performance is my main hit.