Use files to save objects to improve JSP Performance

Source: Internet
Author: User

WithWEBTechnology development, enterprise level 3WebThe application is already very popular.ServletFor example,WebBrowser,ServletThe middle layer and the back-end database server constitute the three-layer structure. The structure is very clear and it brings a lot of convenience for design and development. However, we all know that the connection between the layer and the layer,In addition, a large number of logical operations and Data Reading are completed on the intermediate layer server.,CauseWebThe performance problem has always been a headache for developers. I am developing a document center system and how to improve it.Jsp (preferred for SUN Enterprise applications)I hope you can give more comments on performance.

My idea is to save the object as a file. There are many file formats here, which can beXml (standardization is getting closer and closer)Format, or custom files generated by serialized objects. Here I am talking about the latter. When reading data from the middle layer, it does not read data from the database. Instead, it reads local files and adds new data. The change is the same. This reduces the number of times that the middle-tier server connects to the database server, and uses the hard disk file of the Middle-tier server to read and write data to replace the database operation.Jsp (preferred for SUN Enterprise applications)Performance.

 The specific implementation is described as follows (DocumentFor example, my document data table is saved in the database. The document object is saved as a file on the local hard disk of the intermediate layer server. When you read a document on the reading interface, this page is based on the requested documentIDA document object is generated,Document doc = new Document (ID ),The other attributes of the document areIDObtained from the named file,

FileInputStream FCM = new FileInputStream (doc. getID ());

ObjectInputStream ois = new ObjectInputStream (FCM );

Doc = (Document) OS. readObject ();

When adding or modifying a document:

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 ();

Generate a new file or overwrite the original file. When the user reads this document (in this system, when the document is added or modified, it will be transferred to view this document page immediately),I added the attributes of this document to the database in the background.,In this way, you do not have to wait until all operations are completed before you can see the page.,In this way, the burden on the intermediate layer server is shared.,Because the document table is associated with many views,So when I add or modify a file, I update the file and data table at the same time.,Like comments,Independent tables such as logs,You only need to update the corresponding file.,Wait until the middle layer server is idle at night to update the comment.,Log table.This will bring better results.

The following describes its implementation.,To save an object and copy it out, recreate the object.,This object is required

Implement serialization Interface(Serializableinterface ),For this class,This interface does not need to be implemented by any party

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.