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.
My website www.threes.cn