In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to speed up the application of JSP precompilation, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
In Java Web applications, due to a series of characteristics such as real-time effect of JSP changes, we often use JSP as a page display tool.
In essence, JSP is just a special Java file, which will generate a java file at run time, and then compile a class file for execution.
For a small application, the display time requirements of JSP may not be particularly high, while for medium and large projects, when a large number of JSP pages are involved, a lot of time will be spent on generating java files and compiling class on the first request.
Therefore, for those who consider Tomcat performance optimization, you can consider this item mentioned in this article after you have done JVM tuning, thread pool setting, load balancing, and so on.
To speed up the execution of applications, Tomcat provides a feature internally
JSP precompilation
The so-called precompilation is that before the official use, the JSP file has been compiled to generate a Java (Servlet) file, and then compiled into class. In this way, when the subsequent real request arrives, you don't have to wait for the process.
This function provided by Tomcat is a class in the jasper.jar file:
Org.apache.jasper.JspC
If you have read the debug source code, you can run the class's main method directly. If you don't have the source code on hand, you can use a bat/shell where java-cp xxx.jar includes the dependent jar, then execute the above class, and you will see the following help.
You can compile a JSP file, or you can specify the application project path to compile all the JSP under an application.
When you execute Jspc, you can also specify the output path of the class file.
For the usage of the generated content, we can specify the way in which the configuration in the web.xml is generated, declare the pre-compiled class file in web.xml as servlet, then copy the generated web.xml segment to the application's web.xml, and copy the generated class to the application's classes directory.
Of course, you can also copy the generated class into Tomcat's jsp file generation directory (work), so that you don't need to regenerate it later.
For the implementation of JSP, you can refer to two old articles:
Do you know how Tomcat handles Jsp files?
Modify the secret that the JSP file takes effect in real time
In addition to source code execution and scripting, JSP can also be precompiled through the Ant task.
For more information, please refer to the example provided in the official documentation: http://tomcat.apache.org/tomcat-8.5-doc/jasper-howto.html#Web_Application_Compilation
The main thing is to compile a build.xml of Ant, and then perform the specified task on the command line. The content declared in build.xml, similar to what we have above, declares some class path dependencies, the path to the jsp to be compiled, the path to generate class, and so on.
Show a picture to friends who don't want to jump.
Generated_web.xml is the generated web.xml fragment, which can be copied into our application.
For friends who use Maven, you can use Jspc as a plug-in in pom.xml.
GroupId and articatId are like this.
The above is based on the implementation of the codehus-mojo plug-in, and the original implementation is no longer updated. There are also several plug-in implementations, such as apache-sling. Please refer to this:
Https://sling.apache.org/documentation/development/jspc.html
The basic configuration is as follows:
Org.codehaus.mojo
Jspc-maven-plugin
Jspc
Compile
Then, like the execution of Ant, specify an execution target. You can also specify additional execution parameters, such as file generation paths, and so on.
Of course, if you don't want to use any of these methods, you can also use a purely manual approach and request all the possible pages once after deployment. & _ &
For some Full Profile application servers, such as GlassFish, the option of whether to precompile JSP will be included when the application is deployed. If selected, JSP will be precompiled during deployment. In this case, if there is a compilation problem, the deployment will fail.
In fact, the java and class files generated by JSP compilation are placed in its working directory, such as GlassFish's domain_name/generated/jsp directory, which is generated before the initial request and reduces the waiting time for application access.
After reading the above, do you have any further understanding of how to speed up the application of JSP precompilation? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.