- 转载自
- 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);
- }