Improve JSP page response speed of the seven cheats trick

Source: Internet
Author: User
Tags config sql

Method One: Caching data in the Init () method of the Servlet

After the application server initializes the servlet instance, it invokes the Init () method of the servlet before servicing the client request. In the lifecycle of a servlet, the init () method is invoked only once. System performance can be greatly improved by caching some static data in the Init () method or by completing some time-consuming operations that need to be performed only once.

For example, creating a JDBC Connection pool in the init () method is a good example, assuming that we are using the jdbc2.0 DataSource interface to get a database connection, and that, in general, we need to get a specific data source through Jndi. We can imagine that in a specific application, if a jndi query is executed every time a SQL request is performed, the performance of the system will drop dramatically. The workaround is the following code, which is cached datasource, making it possible for the next SQL call to continue to take advantage of it:

public class ControllerServlet extends HttpServlet{
private javax.sql.DataSource testDS = null;  
public void init(ServletConfig config) throws ServletException {
super.init(config);   
Context ctx = null;  
try{    
ctx = new InitialContext();   
testDS = (javax.sql.DataSource)ctx.lookup("jdbc/testDS");
}catch(NamingException ne){ne.printStackTrace();}
}catch(Exception e){e.printStackTrace();}
} 
public javax.sql.DataSource getTestDS(){ 
 return testDS; 
} 
...
...
}

Method 2: Disable servlet and JSP automatic overloading (auto-reloading)

SERVLET/JSP provides a practical technology, automatic overload technology, which provides developers with a good development environment, when you change the servlet and JSP pages without restarting the application server. However, this technology is a great drain on the resources of the system during the operation of the product, because it will bring a great burden to the JSP engine class loader (ClassLoader). Therefore, turning off the automatic overload feature is a great help to improve system performance.



Related Article

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.