schedule(TimerTask task, long delay)的注释:Schedules the specified task for execution after the specified delay。大意是在延时delay毫秒后执行task。并没有提到重复执行schedule(TimerTask task, long delay, long period)的注释:Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay。大意是在延时delay毫秒后重复的执行task,周期是period毫秒。
想自己写的话 就自己写吧启动项目就加载
http://blog.csdn.net/zhujianpengzha/article/details/8140372如果没用框架,可以使用schedule
<listener>
<listener-class>com.whty.business.JobTimer</listener-class>
</listener>
JobTimer类实现 ServletContextListener接口,其中有个初始化方法,在里面调用你用TimerTask写的定时器即可 //time1,启动时的延时;time2每隔多长时间重复执行一次
timer.schedule(task, time1, time2);
如果是每天10点执行一次,可以在TimerTask run()中判断当前小时 是否是 10点即可,
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
if(hour==10){
//调用你的定时程序 }