Using object file is saved to improve the performance of JSP
With WEB technological development, enterprise-class three-tier Web application has been very popular, as an example to Servlet technology, Web browser, Servlet middle layer, a database server behind this three-tier structure, the structure is very clear on the design and development brought a lot of convenience, but we all know, the connections between layer and layer, coupled with a large number of logic and data read on the intermediate layer server completed, leading to a Web performance issues has been to give developers a headache , I am on my document in the development of a central system on the process of how to improve the performance of JSP written by some of the ideas that everyone speak up.
My idea is to preserve the objects in the form of documents, many of the format of the paper here, it could be in XML format, it can also be a sequence of the object through the self-definition of the document, here I am talking about the latter. Middle layer read data from the database is not read, but reading the local paper, add, modify, as well. Reduced the intermediate layer server database server connecting the frequency of use of the middle layer read and write file servers to replace the hard drive to operate the database and improve the performance of the JSP.
Concrete realization described as follows: Document Object (Document) as an example, I document data stored in the database tables in a single document object to the form of the document in the middle of the drive to preserve a local server, user interface into the reading reading a document, this page under the ID of the requested documents will generate a Document Object, Document doc = new Document (ID), and other attributes of a document from a file named in the document ID access,
FileInputStream fis = new FileInputStream (doc.getID ());
ObjectInputStream ois = new ObjectInputStream (fis);
Doc = (Document) os.readObject ();
Add or modify a document when:
Document doc = new Document ();
Doc.setID (…);
Doc.setTitle (…);
Doc.setKeyWord (…);
……
FileOutputStream fos = new FileOutputStream (doc.getID ());
ObjectOutputStream oos = new ObjectOutputStream (fos);
Oos.writeObject (doc);
Oos.flush ();
A new cover or the original document, the user time to read this document (in this system when the new or revised documents immediately after the end of the document into the browser page), I will be in the background, the text file attributes added to the database, so users do not have to wait until after the completion of the operation of all to see pages, which also assessed the burden of the middle layer server, as a lot of related documents Table view, so when the new or revised I also updated documentation and data sheets, and comments like, this independent log table can be used only on the document can be updated accordingly, until the middle of the night when the server idle again updated reviews, log table. effect of this will be better .
Below explain it to the realization, we should want to save the file and object replication to make it out reconstruction object, and this object must
Implementation sequence of interface (Serializableinterface), for this category, the interface does not require any means to achieve it
Main notice java virtual machine (JVM), will need an object of the sequence of our developers, just implements
Serializable on the other we do not need to do,
Object will be read out or flow into two main categories: ObjectOutputStream and ObjectInputStream.
ObjectOutputStream provide will be used to target output flow into the writeObject, ObjectInputStream
Provide input stream from the object readObject read out method.
Determine whether a class has been sequence, can be used to serialver JDK tools judgement:
C: \ j2sdk
Java.util.TimeZone: static final long serialVersionUID = 3581463369166924961L;
I am here to prepare such a case, we will be read at a glance:
Package com.Test;
Import java.io. *;
Public class Test
(
Public static void main (String [] args)
(
Try
(
FileOutputStream os = new FileOutputStream ( "Test.out");
ObjectOutputStream o = new ObjectOutputStream (os);
Plant plant = new Plant ( "Apple");
O.writeObject (plant);
O.flush ();
FileInputStream fs = new FileInputStream ( "Test.out");
ObjectInputStream oss = new ObjectInputStream (fs);
Plant p = (Plant) oss.readObject ();
System.out.println (p.getName ());
)
Catch (FileNotFoundException
E) (System.out.println ( "FileNotFoundException:" + e.getMessage ());}
Catch (IOException ee) (System.out.println ( "IOException:" + ee.getMessage ());}
Catch (ClassNotFoundException
Ee) (System.out.println ( "IOException:" + ee.getMessage ());}
Class Plant implements Serializable / / internal class implements Serializable interface
(
Private String name;
Public Plant (String pname)
(
Pname = name;
)
Public String getName ()
(
Return name;
)
)
)
)
The result: Apple
Tags: JSP, object, performance








0 Comments to “Using object file is saved to improve the performance of JSP”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.