Seven Tips for improving JSP applications-general Linux technology-Linux programming and kernel information. The following is a detailed description. Are you often complained about slow response to JSP pages? Have you ever wondered whether your WEB applications will be able to withstand the increasing traffic volume when the number of customer visits increases dramatically? This article describes some very practical methods to adjust JSP and servlet. It can make your servlet and JSP page response faster and more scalable. In addition, when the number of users increases, the system load will show a smooth and long trend. In this article, I will use some practical examples and configuration methods to unexpectedly improve the performance of your application. Some tuning techniques are implemented in your programming work. Other technologies are related to the configuration of application servers. In this article, we will describe in detail how to improve the overall performance of your application by adjusting the servlet and JSP pages. Before reading this article, let's assume that you have basic servlet and JSP knowledge.
Method 1: cache data in the servlet init () method
After the application server initializes the servlet instance and provides services for client requests, it will call the init () method of the servlet. In the lifecycle of a servlet, The init () method is called only once. By caching some static data in the init () method or completing some time-consuming operations that only need to be executed once, the system performance can be greatly improved.
For example, establishing a JDBC connection pool in the init () method is an optimal example. Suppose we use the DataSource interface of jdbc2.0 to obtain the database connection. In general, we need to obtain the specific data source through JNDI. We can imagine that in a specific application, if every SQL request needs to execute a JNDI query, the system performance will drop sharply. The solution is the following code, which caches DataSource so that the next SQL call can continue to use it: