in general ,Jasper The mechanism of automatic detection is relatively simple , Rely on a background thread to continuously detect JSP File and compiled class Whether the last modification time of the file is the same , If it's the same, it's not changed , But if it's different, it needs to be recompiled . In fact, because of Tomcat The name of the deployed project JSP Other pages may have been introduced , Or introduce other jar package , And these resources may be remote resources , So the actual processing will be more complicated , It is also necessary to traverse and detect whether these introduced different resources have been modified .

The picture above is a sketch of an image , We know Tomcat There are four levels of containers in the architecture ,Engine、Host、Context and Wrapper, and jsp Compilation corresponds to wrapper Level , So pass StandardWrapper Constantly perform tasks to call jasper, and jasper Then continuously check and verify various local and remote resources , Recompile as soon as you find that you need to recompile . Let's take a look at how to achieve it .

First , A background execution thread is required ,Tomcat There is a special thread to handle different containers background Mission , To perform some background tasks in different containers, just rewrite backgroundProcess Method can be realized , because JspServlet Corresponding to Wrapper Level , So we need to StandardWrapper Rewriting in backgroundProcess, It will call the implementation PeriodicEventListener Interface Servlet, among JspServlet And that's what happened PeriodicEventListener Interface , This interface has only one periodicEvent Method , The specific detection logic can be realized in this method .

secondly , Check to determine the basis of recompilation ? Recompile is to recompile jsp become java And then become class, And the condition that triggers this action is when we modify a jsp After the document , Or something jsp After the resource introduced by the file is modified , Will trigger the recompile action , So the best judgment is based on jsp Or the last modification time of the resource lastmodified attribute , The normal order is jsp After compiling, it generates class file , Put this class Of documents lastmodified Property set to jsp Of documents lastmodified, At this point, the two files lastmodified The properties are the same , When we change jsp After the file is saved ,jsp Of lastmodified Property is set to the current time , At this time, by judging the lastmodified Property determines whether to recompile . After recompilation jsp And class Of documents lastmodified Property is set to the same again . For the introduced resources , In memory, the resource that was introduced during the last compilation is maintained lastmodified attribute , Constantly access to the introduction of resources lastmodified Property and the corresponding in memory lastmodified Properties are compared , It's also easy to determine if you need to recompile .

Last , How to detect local and remote resources respectively ? For local resources , Use java.io.File Class can be easily implemented for a JSP Of documents or other documents lastmodified Attribute reading . For remote resources , such as jar package , For the convenience of handling jar Included properties , Use java.net.URL It is easy to operate , It contains a lot of protocols , For example, common jar、file、ftp Such agreement , It's quite convenient to use ,

URL includeUrl = new URL("jar:http://hostname/third.jar!/");

URLConnection iuc = includeUrl.openConnection();

long includeLastModified = ((JarURLConnection) iuc).getJarEntry().getTime();

It only takes three steps to complete the remote jar The last modification time of package reading and fetching . Of course URL It also supports the reading of local file resources , So it's a good resource to read abstract objects ,Tomcat The introduction of resources in the management are used URL As the object of operation .

This section discusses Jasper Implementation of automatic detection mechanism , Automatic detection mechanism has brought us a good experience , We don't have to change it ourselves jsp After that, I will perform the compilation operation myself , It is tomcat adopt jasper Help us check the compilation operation regularly .

jsp More articles on automatic compilation mechanism

  1. jsp Self active compilation mechanism

    in general ,Jasper The mechanism of self active detection is relatively simple , Rely on a background thread to continuously detect JSP File and compiled class Whether the last change time of the file is the same , If it's the same, I don't think it's changed . But if it's different, it needs to be compiled again . Actually, because in T ...

  2. JSP Compile instruction

    JSP Yes 3 Two compiler instructions , It's a notice JSP News from the engine , It doesn't generate output directly . Compile instructions have default values , There is no need to set values for each instruction . There are three common compilation instructions : page: Instructions for the current page . include: Specify to include another page ...

  3. weblogic Yes JSP precompile 、weblogic Read JSP The compiled class file 、ant in weblogic.jspc precompile JSP

    We all know that weblogic in JSP It's compiled every time it's accessed for the first time , This leads to the first visit to a JSP When it comes to performance degradation , Sometimes we want to JSP Compiled into class And then package it in jar Hide in JSP The function of , Let's introduce ...

  4. < About JSP technology > Operation mechanism and syntax overview ( Attached to this Tongji school ACM I make complaints about the finals )

    ( One )JSP The mechanism of operation JSP It is based on Servlet Dynamic web technology based on standard function , They all embed script code in the normal web page file , Used to generate dynamic content , But and ASP The difference is JSP Embedded in the file is Java Code and JS ...

  5. Web The automation framework is complete demo Every bit of (excel Function case parameterization + Hierarchical design of business functions +mysql Data storage encapsulation + Screenshot + journal + Test report + Docking defect management system + Automatically compile the deployment environment + Automatic verification false、error Case study )

    The title is big , I want to say a lot , I don't know where to start ~~ Go straight to the point Individuals are also due to the current situation of the company's personnel and the special circumstances of the project , After the middle of this year web Automation : The whole reason is simple , I just want to be lazy . The coolie of colleagues is also relieved ...

  6. Tomcat Set auto compilation , Automatic release , Automatic deployment

    Tomcat The server It has a common function : That is, automatic compilation , Automatic release , Automatic deployment capabilities . problem : When we first released the program , Let's add, delete and change Servelt,Java,.xml Wait for the documents , They have to be rebooted Tomcat, If the project is huge ...

  7. Talking about java Compiling mechanism and running mechanism

    How source files and bytecodes are made up Source file : Expand the following java This is the document of java The source file . Java Source compilation consists of the following three procedures : 1. Analyze and input to symbol table 2. Annotation Processing 3. Semantic analysis and generation class file flow chart ...

  8. eclipse Automatic compilation

    Automatic compilation : Yes java Application doesn't make sense , Yes web applications , When you change the code , Will automatically help you compile and publish to web In the container , The restart of the province web Container . build: compile ,Eclipse The compilation of is based on the judgment mechanism of timestamp .c ...

  9. Use devenv.exe Automatically compile projects

    Because mobile games use cocos2d-x lua Development , Fight PC When the version is submitted for testing , There are some environment configuration changes that need to be made , It's a lot of trouble to get out of the bag , First modify the file and then generate . If you can package it automatically , Before each packaging, the files that need to be modified are processed ...

Random recommendation

  1. [Android Pro] Normal Permissions

    As of API level 23, the following permissions are classified as PROTECTION_NORMAL: ACCESS_LOCATION_E ...

  2. js Regular matching can only input significant number and decimal point

    var reg = /^\d+\.?\d*$/; if(value.search(/^\d+\.?\d*$/)===0 && parseFloat(value)>0){// You can only lose ...

  3. PostgreSQL Replication Chapter 10 To configure Slony(1)

    stay PostgreSQL In the field ,Slony Is one of the most extensive replication solutions . It's not just one of the oldest replication implementations , But it's also the one with the most support from external tools , for example PgAdmin3 etc. . In this chapter , We're going to delve into Slony And learn ...

  4. [HDOJ5573]Binary Tree( Looking for a regular , greedy )

    Topic link :http://acm.hdu.edu.cn/showproblem.php?pid=5573 This question …… I can't find the law yet , Two first TLE The code of , One dfs A barometric enumeration . #include ...

  5. js Array weight removal Of 5 Methods

    Ten thousand arrays ,4 Duplicate items , First of all, post your grades . 1.3 millisecond 2.115 millisecond 3.71 millisecond 4.6 millisecond 1. Hashtable 2.JQuery ( The fastest way is to use JQuery This sentence is a screenshot with ... actually Jq The slowest. ) 3. ...

  6. Due to the policy set by the Administrator , The disk is offline -Win 2008 R2

    Screenshot of the problem : Made a novel website www.114369.cn, Using a virtual machine , System is Win 2008 R2, After entering the server, I found that there was a problem with the disk Only c disc , No, d disc , Tips : Due to the policy set by the Administrator , The disk is offline solve ...

  7. ECSHOP The whole site of the mall is customized TITLE Title Setting

    about SEO Come on , The number of titles that can be customized will be greatly increased SEO effect , Increase the flow of independent Mall , Today, Xiaobian collected it from the Internet ecshop User defined code of the whole station , Very complete ! 1.Ecshop How to customize the commodity classification page Title It's been discovered recently that ...

  8. Hopcroft-Karp Algorithm template

    #include <cstdio> #include <cstring> #include <vector> #include <queue> #inc ...

  9. keycloak Manage user rights

    One . stay keycloak Basic data is defined in 1.realm If multiple modules use different user permissions , Just divide realm If multiple modules share a set of user permissions , Just one by one realm 2. Each module is a client-app 3. ...

  10. MIDAS.dll When something goes wrong (Error loading MIDAS.DLL.)

    DELPHI The program that you write will come out ---------------------------Pmain---------------------------Error loading MIDAS.DLL.--- ...