Overview
In this article, Rahul Chaudhary will describe the use of performance tuning technology (PTT performance-tuning techniques) to improve the performance of servlets and JSP, so as to improve the performance of your J2EE application. I assume that the reader has basic knowledge about servlets and JSPs.
By Rahul Chaudhary
Translator: guipei
Is your J2EE application running slowly? Can they meet sufficient pressure? This article describes how to use performance tuning technology (PTT performance-tuning techniques) in developing high-performance applications and JSP and servlets ). Using these technologies, you can build a faster and more robust system to meet the needs of more users or more requests. In this article, I will take you through practical practices to test how to adjust the performance to improve the performance of your servlets and JSP pages, and ultimately improve the performance of your J2EE application. Some of these technologies are used in the development process, that is, they are suitable for system design or code writing. Other technologies are related to configuration.
Method 1: Use HttpServlet init () to cache data
The application server calls the servlet init () method before constructing the servlet and receives any request. It is called only once in the servlet lifecycle. The Init () method caches static data or performs operations that consume a large amount of resources to improve performance during initialization.
For example, using the jdbc connection pool is the best practice when you call the javax. SQL. DataSource interface. DataSource is obtained through the JNDI (java Naming and service interface) tree. If the DataSource is searched for during each SQL call, it will seriously affect the performance of the application service. Servlet's init () method will be used to obtain DataSource and cache it for future use.
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)
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.