Java???????????---?????
???????????? ???????[ 2012/11/2 10:11:00 ] ????????
?????????????У?????????Щ?????????????????5??????????????????Σ????????????У?????????????.??????????????????????????????????????????????????????????д??????????????????????????????????????????????и????????ж?.????????????????????????????????????????????jdk???????.
????Java.util.Timer??????????????????????????????????е?????.??????????????λ????????????.???м???????????????????£?
????cancel()????????????????????е????????????
????schedule(TimerTask task?? Date time)????????????????????????????
????schedule(TimerTask task?? Date firstTime?? long period)????????????????????????儷?????????????????С?
????schedule(TimerTask task?? long delay)???????????????????????????
????schedule(TimerTask task?? long delay?? long period)??????????????????????????????????????????С?
????scheduleAtFixedRate(TimerTask task?? Date firstTime?? long period)????????????????????????儷??????????????????С?
????scheduleAtFixedRate(TimerTask task?? long delay?? long period)????????????????????????????????????????????С?
??????????????Timer??????????У??????ж??漰????TimerTask??.??TimerTask???????????????Timer??????????????????????????λ??ε?????.???????????????????????????????
????cancel()???????????????
????run()???????????????е???????????????????????????
???????Timer??TimerTask????????????????????????????????????????????????е?????????????????????????????У??????????????÷?????????С???????????????????????????????????????е???????ServletContextListener????????????????????????ServletContext????????????????????????Web???????????????Servlet????????????Web??????????ServletContextEvent????????????ServletContextListener????????漰???????????????
????contextInitialized(ServletContextEvent sce);?????;
????contextDestroyed(ServletContextEvent sce)????
??????????????????????????????????????????????????????????????
package com.boco.transnms.server.bo.stat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class NFDFlightDataTaskListener implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
//??????????
}
@Override
//?????????????д??????
public void contextInitialized(ServletContextEvent arg0) {
new TimerManager();
}
}
//???е?????
class NFDFlightDataTimerTask extends TimerTask{
@Override
//???????????????????????
public void run() {
System.out.println("?????????:"+System.currentTimeMillis());
}
}
class TimerManager{
private static final long PERIOD_DAY=6 * 1000; //?????????????
public TimerManager() {
Timer timer = new Timer(); //??????????
NFDFlightDataTimerTask task = new NFDFlightDataTimerTask(); //???е?????
//??????????????????????儷?????????????????С?
timer.schedule(task??new Date()??PERIOD_DAY);
}
}
??????????????????????????????????????????????????web.xml????????????????????
<listener>
<!—???????????????????????????-->
<listener-class>
com.boco.transnms.server.bo.stat.NFDFlightDataTaskListener
</listener-class>
</listener>
????????????????????????????????????????????????????6?????????????“?????????***”??
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11