代码实例
package oa.epoint.com.watchFile;import java.util.Date;import java.util.Timer;import java.util.TimerTask;/** * : 文件监控之定时器 */public class FileScheduler { //定时器设置 private final Timer timer; //构造方法 public FileScheduler(){ timer = new Timer();; } //设置守护线程 public FileScheduler(boolean isDaemon){ // 是否为守护线程 timer = new Timer(isDaemon); } /** * Methods : 为定时器分配可执行任务 */ public void schedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 重新执行任务 */ private void reSchedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 停止当前定时器 */ public void cancle(){ timer.cancel(); } /** * :停止当前定时器 */ 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;/** * : 文件监控之定时器 */public class FileScheduler { //定时器设置 private final Timer timer; //构造方法 public FileScheduler(){ timer = new Timer();; } //设置守护线程 public FileScheduler(boolean isDaemon){ // 是否为守护线程 timer = new Timer(isDaemon); } /** * Methods : 为定时器分配可执行任务 */ public void schedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 重新执行任务 */ private void reSchedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 停止当前定时器 */ public void cancle(){ timer.cancel(); } /** * :停止当前定时器 */ 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;/** * : 文件监控之定时器 */public class FileScheduler { //定时器设置 private final Timer timer; //构造方法 public FileScheduler(){ timer = new Timer();; } //设置守护线程 public FileScheduler(boolean isDaemon){ // 是否为守护线程 timer = new Timer(isDaemon); } /** * Methods : 为定时器分配可执行任务 */ public void schedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 重新执行任务 */ private void reSchedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 停止当前定时器 */ public void cancle(){ timer.cancel(); } /** * :停止当前定时器 */ 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;/** * : 文件监控之定时器 */public class FileScheduler { //定时器设置 private final Timer timer; //构造方法 public FileScheduler(){ timer = new Timer();; } //设置守护线程 public FileScheduler(boolean isDaemon){ // 是否为守护线程 timer = new Timer(isDaemon); } /** * Methods : 为定时器分配可执行任务 */ public void schedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 重新执行任务 */ private void reSchedule(Runnable task,TimeStep step){ Date time = step.next(); SchedulerTimerTask ti sk = new SchedulerTimerTask(task,step); // 安排在指定的时间 time 执行指定的任务 ti sk timer.schedule(ti sk, time); } /** * Methods : 停止当前定时器 */ public void cancle(){ timer.cancel(); } /** * :停止当前定时器 */ 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); } } } 继续阅读与本文标签相同的文章
上一篇 :
phoenix操作hbase
下一篇 :
mysql全表抽取到MPP
-
用js来实现那些数据结构11(字典)
2026-05-25栏目: 教程
-
用js来实现那些数据结构10(集合02-集合的操作)
2026-05-25栏目: 教程
-
用js来实现那些数据结构09(集合01-集合的实现)
2026-05-25栏目: 教程
-
用js来实现那些数据结构08(链表02-双向链表)
2026-05-25栏目: 教程
-
用js来实现那些数据结构07(链表01-链表的实现)
2026-05-25栏目: 教程
