现在请看清楚我的要求:每次执行结束后,等3秒再执行下一次
6 个解决方案
#1
支持。
#2
直接写代码
循环调用任务执行函数+sleep(3秒) 不就ok了?
为啥非要用牛刀啥鸡?
循环调用任务执行函数+sleep(3秒) 不就ok了?
为啥非要用牛刀啥鸡?
#3
public class Timer1 {
public static void main(String[] args) {
Timer timer=new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("aaaaaaaa");
}
}, 0, 3000);//0:开始时间 3000:间隔时间,毫秒级
}
}
public static void main(String[] args) {
Timer timer=new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("aaaaaaaa");
}
}, 0, 3000);//0:开始时间 3000:间隔时间,毫秒级
}
}
#4
请问如何做呢?
问题是公司一整套项目程序代码都是用quartz的,我现在中途杀出一个Timer出来,就搞得代码很不统一了
#5
SchedulerFactory sf = new StdSchedulerFactory();
sched = sf.getScheduler();
JobDetail deleteTmpFilesJob = new JobDetail("delete tmp word file ",
"group1", DeleteTmpWordFileJob.class);
SimpleTrigger trigger = new SimpleTrigger(
"trigger for deleting tmp word file ", "group1");
trigger.setRepeatInterval(1000 * 60 * 60 * 24 * 15);// 15天运行一次
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);// 无限次运行
sched.scheduleJob(deleteTmpFilesJob, trigger);
sched.start();
sched = sf.getScheduler();
JobDetail deleteTmpFilesJob = new JobDetail("delete tmp word file ",
"group1", DeleteTmpWordFileJob.class);
SimpleTrigger trigger = new SimpleTrigger(
"trigger for deleting tmp word file ", "group1");
trigger.setRepeatInterval(1000 * 60 * 60 * 24 * 15);// 15天运行一次
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);// 无限次运行
sched.scheduleJob(deleteTmpFilesJob, trigger);
sched.start();
#6
StatefulJob 好像要实现这个接口
http://www.javaeye.com/topic/162088
http://www.javaeye.com/topic/162088
#1
支持。
#2
直接写代码
循环调用任务执行函数+sleep(3秒) 不就ok了?
为啥非要用牛刀啥鸡?
循环调用任务执行函数+sleep(3秒) 不就ok了?
为啥非要用牛刀啥鸡?
#3
public class Timer1 {
public static void main(String[] args) {
Timer timer=new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("aaaaaaaa");
}
}, 0, 3000);//0:开始时间 3000:间隔时间,毫秒级
}
}
public static void main(String[] args) {
Timer timer=new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("aaaaaaaa");
}
}, 0, 3000);//0:开始时间 3000:间隔时间,毫秒级
}
}
#4
请问如何做呢?
问题是公司一整套项目程序代码都是用quartz的,我现在中途杀出一个Timer出来,就搞得代码很不统一了
#5
SchedulerFactory sf = new StdSchedulerFactory();
sched = sf.getScheduler();
JobDetail deleteTmpFilesJob = new JobDetail("delete tmp word file ",
"group1", DeleteTmpWordFileJob.class);
SimpleTrigger trigger = new SimpleTrigger(
"trigger for deleting tmp word file ", "group1");
trigger.setRepeatInterval(1000 * 60 * 60 * 24 * 15);// 15天运行一次
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);// 无限次运行
sched.scheduleJob(deleteTmpFilesJob, trigger);
sched.start();
sched = sf.getScheduler();
JobDetail deleteTmpFilesJob = new JobDetail("delete tmp word file ",
"group1", DeleteTmpWordFileJob.class);
SimpleTrigger trigger = new SimpleTrigger(
"trigger for deleting tmp word file ", "group1");
trigger.setRepeatInterval(1000 * 60 * 60 * 24 * 15);// 15天运行一次
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);// 无限次运行
sched.scheduleJob(deleteTmpFilesJob, trigger);
sched.start();
#6
StatefulJob 好像要实现这个接口
http://www.javaeye.com/topic/162088
http://www.javaeye.com/topic/162088