課程
/后端開發
/Java
/Java定時任務調度工具詳解之Timer篇
有源碼嗎?
2017-05-17
源自:Java定時任務調度工具詳解之Timer篇 3-1
正在回答
package?com.may.seventy; import?java.text.SimpleDateFormat; import?java.util.Calendar; import?java.util.TimerTask; /** ?*?Created?by?junfeng?on?17/5/17. ?*/ public?class?MyTimerTask?extends?TimerTask?{ ????private?String?name; ????public?MyTimerTask(String?inputName){ ????????name?=?inputName; ????} ????@Override ????public?void?run()?{ ????????Calendar?calendar?=?Calendar.getInstance(); ????????SimpleDateFormat?sf?=?new?SimpleDateFormat("yyyy-MM-dd?HH:mm:ss"); ????????System.out.println("Current?exec?name?is:"+name); ????} ????public?String?getName()?{ ????????return?name; ????} ????public?void?setName(String?name)?{ ????????this.name?=?name; ????} }
package?com.may.seventy; import?java.text.SimpleDateFormat; import?java.util.Calendar; import?java.util.Timer; /** ?*?Created?by?junfeng?on?17/5/17. ?*/ public?class?MyTimer?{ ????public?static?void?main(String[]?args)?{ ????????Timer?timer?=?new?Timer(); ????????MyTimerTask?myTimerTask?=?new?MyTimerTask("NO.1"); ????????//timer.schedule(myTimerTask,1000L,5000l); ????????Calendar?calendar?=?Calendar.getInstance(); ????????SimpleDateFormat?sf?=?new?SimpleDateFormat("yyyy-MM-dd?HH:mm:ss"); ????????System.out.println(sf.format(calendar.getTime())); ????????calendar.add(Calendar.SECOND,3); //????????myTimerTask.setName("test1"); //????????timer.schedule(myTimerTask,calendar.getTime()); //????????myTimerTask.setName("test2"); //????????timer.schedule(myTimerTask,calendar.getTime(),3000); ????????myTimerTask.setName("test3"); ????????timer.schedule(myTimerTask,2000); ????} }
慕的地6384686 提問者
舉報
Java定時任務調度工具詳解之Timer篇
1 回答源碼提供
3 回答這個課程有原碼嗎
3 回答有且只有一個后臺線程。。意思是說不能new 兩個timer 分別去調用任務嗎
2 回答重復的方法嗎
1 回答沒有看到延遲的那個參數
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-05-17