Tomcat Listener Servletcontextlistener Load Web application Data __web

Source: Internet
Author: User

In many Java projects, you need to load some data into memory at startup (read the infrequently changed content into memory, so the server does not need to slow disk I/O when responding to requests, such as system parameters, configuration file contents, and so on, and how the data is loaded when the web is started. Now let bloggers take a look at this content:

ServletContext Introduction: Is a global storage space for information, the server began, it exists, the server is closed, it is released.

Servletcontextlistener is a ServletContext listener who listens to two events about ServletContext-initialization and destruction. So we took advantage of this relationship to load the data (in the database or in the configuration file) into memory, where the Servletcontextlistener and destruction methods are contextinitialized,contextdestroyed, Using this method, you can load data into memory when a Web program starts: Bloggers are so useful in projects:


But the above steps are not finished, and the final step is to include the following listening configuration in the Web.xml file (to write the full path of this listener Class):

<listener>   
       <listener-class > Myservletcontextlistener < listener-class>   
    <listener>

To sum up, I took care of this little knowledge of loading memory configuration,

One thing to note is the loading sequence,

1. If you load the spring container first, you may receive a class that requires data from memory activity to be completely fetched.

2, if the first load above this monitoring, generally will not have any problems, but the required objects can not belong to spring container, only their own new,

So notice that the two o'clock is OK,

Hey, I hope this article can help people in need, I wish you a happy work study. More content please pay attention to my personal blog: Mirrors Blog reproduced please bring the source link, thank you, www.noreplace.com

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.