Java Timer????????á???????????У?
???????????? ???????[ 2015/8/5 13:42:11 ] ????????????????
???????????????????????????????java??Timer???????ж??????????????й?Timer???Щ???????
???????Timer???????????????????TimerTask?????????????run??????????????????TimerTask????????????????????????:
????Timer timer = new Timer();
????timer.schedule(new TimerTask() {
????public void run() {
????System.out.println("11232");
????}
????}?? 200000 ?? 1000);
?????????????????TimerTask(???????????????TimerTask?????TimerTask????????Timer????????? Timer?б??????????????Timer??????????????????????)??????дrun??????20s?????У?????????Σ???????????? timer?????????????timerTask?????timerTask??????????壬????timer?????????????????????????ж????run ?????????????????????????????????Runnable???????????????????????????????????????????
?????????timer?????????????????Timer??????Щ??????????
????1?????????????????task??????delay(ms)??????е??????????????Ρ?
????public void schedule(TimerTask task?? long delay)
????2?????????????time???????Ρ?
????public void schedule(TimerTask task?? Date time)
????3?????????????????task????delay??ms????????????ε??????????period??ms????????????
????public void schedule(TimerTask task?? long delay?? long period)
????4???????????????????????????????????????????ε???????
????public void schedule(TimerTask task?? Date firstTime?? long period)
????5?????????task????delay(ms)????????????????period(ms)??ε????ò????????schedule?????????????????????????????????schedule????????????е?????????????????????????????????? + ????????scheduleAtFixedRate?????????????????е????????????????????е????+ ??????????????е??????????????????????????磺schedule??????5s??????????????5??10??15??20??Щ???????????????????????ЩCPU???????δ???????????????8s???????ε???????schedule???????????????????????????13s???????10s???????п????′????20s????????????λ??Σ???scheduleAtFixedRate????????????????????????????????????????????8s?????????????????????10s??????????????????2s??????????????????У??????????????????????????????????
????public void scheduleAtFixedRate(TimerTask task?? long delay?? long period)
????6?????????????????????ε??????????????Date??????????????????????????????????л?????????Щ?????
????public void scheduleAtFixedRate(TimerTask task?? Date firstTime??long period)
?????????
?????????Timer????????м????
??????????1????ι????????????Tiemer??????????????????
????public Timer() {
????this("Timer-" + serialNumber());
????}
?????????????????????????????????timer??????????????????cancel??????timer???????
??????????2??????????????????????????????????????????????????
????public Timer(boolean isDaemon) {
????this("Timer-" + serialNumber()?? isDaemon);
????}
??????????????????????????????timer?????
????public Timer(String name?? boolean isDaemon) {
????thread.setName(name);
????thread.setDaemon(isDaemon);
????thread.start();
????}
?????????????thread?????thread????????????????????????Timer???У???????????thread????????
????private TimerThread thread = new TimerThread(queue);
??????
???·???
??????????????????
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