In the task of achieving the web plan
Abstract: In the web to achieve mission-planning
</ Td> </ tr> <tr> <td width="473" height="35" valign="top" class="ArticleTeitle">
Package test.timer.MyListener;
Import javax.servlet.ServletContextListener;
Import javax.servlet.ServletContextEvent;
Import java.util.TimerTask;
Import java.util.Timer;
Public class MyListener implements ServletContextListener (
Private java.util.Timer timer = null;
Public void contextInitialized (ServletContextEvent event) (
TimerTask task = new TimerTask () (
Public void run () (
System.out.println ( "Hi");
)
);
Timer = new Timer ();
Event.getServletContext (). Log ( "Timer has been initiated");
Timer.schedule (task, 0, 500);
Event.getServletContext (). Log ( "has been added task plan");
)
Public void contextDestroyed (ServletContextEvent event) (
Timer.cancel ();
Event.getServletContext (). Log ( "Timer closed");
)
) / / Timer on the Web operation in the entire project life cycle, the
Finally, you add a few web.xml:
<listener>
<listener-class> Test.timer.MyListener </ listener-class>
</ Listener>
</ Td> <td width="211" valign="top" class="ArticleTeitle">
</ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle">
↑ Back
Tags: java web






