Take two steps: (1). Two methods for implementing the Javax.servlet.ServletContextListener Interface: contextinitialized () and contextdestroyed () contextinitialized () : When the servlet container starts, it executes contextdestroyed (): Executes when the servlet container stops (2). Add a program in contextinitialized () that requires listening, and the Java.util.Timer schedule () method to control how often the listener executes
DEMO (This is one of my SMS reply to listen to the program prototype, streamlined a bit)
public class Replytask extends TimerTask {public void dosomething () {System.out.println ("[SYS] SMS reply Listener ru Nning "); }
public void Run () {dosomething (); }}
Put the compiled class file into the web-inf/classes and don't forget to add a listener statement to the web.xml of the current Web application in the servlet container:
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.