【轉】java 定時執行任務練習
-
- 轉載自http://blog.csdn.net/johnsonvily/article/details/6161147
-
- public void contextInitialized(ServletContextEvent sce) {
- timer = new Timer();
- Calendar calendar = Calendar.getInstance();
- // 指定01:00:00點執行
- calendar.set(Calendar.HOUR_OF_DAY, 1);
- calendar.set(Calendar.MINUTE, 0);
- calendar.set(Calendar.SECOND, 0);
- Date date = calendar.getTime();
- timer = new Timer();
- timer.schedule(new NoticeTask(),date);
- // 若需循環執行,需改成如下代碼
- // 任務執行週期(毫秒)
- // Long period = Long.valueOf(24 * 60 * 60 * 1000);
- // timer.schedule(new NoticeTask(), date, period);
- }
歡迎關注本站公眾號,獲取更多信息