标签:des style blog java color re
import java.util.Timer; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class TestListener implements ServletContextListener { private Timer timer = null; public void contextInitialized(ServletContextEvent event) { timer = new Timer(true); timer.schedule(new TestTimer(), 0, 86400000);//milliseconds } public void contextDestroyed(ServletContextEvent event) { timer.cancel(); } } ------------------------------------------ import java.util.TimerTask; public class TestTimer extends TimerTask { public void run() { // do something ... } } ------------------------------------------ web.xml: <listener> <listener-class>test.TestListener</listener-class> </listener>
Tomcat启动就执行特定方法,布布扣,bubuko.com
标签:des style blog java color re
原文地址:http://www.cnblogs.com/azhqiang/p/3855217.html