代码实例
package oa.epoint.com.watchFile;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
/**
* Title: 文件监控之定时器
*/
public class FileScheduler {
private final Timer timer;
public FileScheduler(){
timer = new Timer();;
}
public FileScheduler(boolean isDaemon){
timer = new Timer(isDaemon);
}
/**
* MethodsTitle: 为定时器分配可执行任务
*/
public void schedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 重新执行任务
*/
private void reSchedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 停止当前定时器
*/
public void cancle(){
timer.cancel();
}
/**
* Title:停止当前定时器
*/
private class SchedulerTimerTask extends TimerTask{
private Runnable task;
private TimeStep step;
public SchedulerTimerTask(Runnable task,TimeStep step){
this.task = task;
this.step = step;
}
public void run() {
task.run();
reSchedule(task, step);
}
}
}
package oa.epoint.com.watchFile;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
/**
* Title: 文件监控之定时器
*/
public class FileScheduler {
private final Timer timer;
public FileScheduler(){
timer = new Timer();;
}
public FileScheduler(boolean isDaemon){
timer = new Timer(isDaemon);
}
/**
* MethodsTitle: 为定时器分配可执行任务
*/
public void schedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 重新执行任务
*/
private void reSchedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 停止当前定时器
*/
public void cancle(){
timer.cancel();
}
/**
* Title:停止当前定时器
*/
private class SchedulerTimerTask extends TimerTask{
private Runnable task;
private TimeStep step;
public SchedulerTimerTask(Runnable task,TimeStep step){
this.task = task;
this.step = step;
}
public void run() {
task.run();
reSchedule(task, step);
}
}
}
package oa.epoint.com.watchFile;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
/**
* Title: 文件监控之定时器
*/
public class FileScheduler {
private final Timer timer;
public FileScheduler(){
timer = new Timer();;
}
public FileScheduler(boolean isDaemon){
timer = new Timer(isDaemon);
}
/**
* MethodsTitle: 为定时器分配可执行任务
*/
public void schedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 重新执行任务
*/
private void reSchedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 停止当前定时器
*/
public void cancle(){
timer.cancel();
}
/**
* Title:停止当前定时器
*/
private class SchedulerTimerTask extends TimerTask{
private Runnable task;
private TimeStep step;
public SchedulerTimerTask(Runnable task,TimeStep step){
this.task = task;
this.step = step;
}
public void run() {
task.run();
reSchedule(task, step);
}
}
}
package oa.epoint.com.watchFile;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
/**
* Title: 文件监控之定时器
*/
public class FileScheduler {
private final Timer timer;
public FileScheduler(){
timer = new Timer();;
}
public FileScheduler(boolean isDaemon){
timer = new Timer(isDaemon);
}
/**
* MethodsTitle: 为定时器分配可执行任务
*/
public void schedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 重新执行任务
*/
private void reSchedule(Runnable task,TimeStep step){
Date time = step.next();
SchedulerTimerTask timeTask = new SchedulerTimerTask(task,step);
timer.schedule(timeTask, time);
}
/**
* MethodsTitle: 停止当前定时器
*/
public void cancle(){
timer.cancel();
}
/**
* Title:停止当前定时器
*/
private class SchedulerTimerTask extends TimerTask{
private Runnable task;
private TimeStep step;
public SchedulerTimerTask(Runnable task,TimeStep step){
this.task = task;
this.step = step;
}
public void run() {
task.run();
reSchedule(task, step);
}
}
}