Recently paying attention to XML, care about the efficiency of various pop parsing technology, when the test program is running time, encounter some difficulties, let's take a look at the questions I put. -------------------------------------------------- ---------------------------
In a class, there is a method called Test () needs to be called by JSP (TEST () main task is system.out.print ()), so add "long lasting = system" in the Test () method. .CurrentTimeMillis (), "Syst means.Println (" Run Time: " (" runtime: " ". ")".
The Test () method is then changed to the main () method to separate test classes, the JSP end code makes the corresponding adjustment to access the main () method. The strange thing happened, after repeated testing, using JSP access to Main () method consumes 451 milliseconds, while running this class consumes 2,864 milliseconds.
Why is this this? Is it the reason for a web container? -------------------------------------------------- ---------------------------
In a very high forum, I got some answers, I also summed up some, please see the official to express the opinion: When I request JSP, the web container sends the JSP to the compiler, compiles to servlet. Then the servlet and other classes (such as the class you write) are then cached in the web container, then put in memory, and finally return the response result to the client; and all of the JSP's subsequent requests, the web container will automatically load the cache. The Web container will not re-execute and construct cache unless JSP or class is modified. The class is not the same, because there is no web container cache support, each run needs to be recompiled and read into memory, so it is slow. In addition, according to the test, the time and alone work class are similar when the JSP end is called, and this is also confirmed to explain the above explanation.
Attach the source program class: package com.test; import org.xml.sax. *; Import org.xml.sax.helpers. *; Import javax.xml.parsers. *;
Public class myxmlreader extends defaulthandler {
Java.util.stack tags = new java.util.stack ();
Public myXmlreader () {super ();
public static void main (String args []) {long lasting = System.currentTimeMillis (); try {SAXParserFactory sf = SAXParserFactory.newInstance (); SAXParser sp = sf.newSAXParser (); MyXMLReader reader = new MyXMLReader (); sp. PARSE ("DATA.XML"), Reader;} catch (Exception E) {E.PrintStackTrace ();} system.out.println ("Running time:" (system.currenttimemillis () () - lasting "Mix");} public void characters (char ch [], int start, int length) throws saxexception {
// From the stack information String Tag = (String) tags.peek (); if (tag.equals ("no")) {system.out.print ("license plate number:" new string (ch , start, length));} if (tag.equals ("addr")) {system.out.println ("Address: New String (CH, Start, Length));}}
Public void startElement (String Uri, String Localname, String Qname, Attributes Attrs) {tags.push (qname);}}
JSP: <% @ Page ContentType = "text / html; charset = GB2312"%> <% @ page import = "com.test. *"%>
<% Long lasting = system.currenttimemillis ();%>
<% string args [] = {"}; myxmlreader.main (args);%> body> html> (please ! Note that reference, posted this article should indicate author: Rosen Jiang and source: http: //blog.9cbs.net/rosen)