⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scheduler.java

📁 SAP这个系统的一个转换器
💻 JAVA
字号:
package com.idoc.timer;/** * <p>Title: IDOC Interface</p> * <p>Description: IDOC 转换器</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: SiChuan XinHua</p> * @author Richary * @version 1.0 */import java.util.Date;import java.util.Timer;import java.util.TimerTask;public class Scheduler {  class SchedulerTimerTask extends TimerTask {      private SchedulerTask schedulerTask;      private ScheduleIterator iterator;      private String type = "";      public SchedulerTimerTask(SchedulerTask schedulerTask,              ScheduleIterator iterator,String type) {          this.schedulerTask = schedulerTask;          this.iterator = iterator;          this.type = type;      }      public void run() {          schedulerTask.run();          reschedule(schedulerTask, iterator,type);      }  }  private final Timer timer = new Timer();  public Scheduler() {  }  /**   * Terminates this <code>Scheduler</code>, discarding any currently scheduled tasks. Does not interfere with a currently executing task (if it exists). Once a scheduler has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.   * <p>   * Note that calling this method from within the run method of a scheduler task that was invoked by this scheduler absolutely guarantees that the ongoing task execution is the last task execution that will ever be performed by this scheduler.   * <p>   * This method may be called repeatedly; the second and subsequent calls have no effect.   */  public void cancel() {          timer.cancel();      }  /**   * Schedules the specified task for execution according to the specified schedule. If times specified by the <code>ScheduleIterator</code> are in the past they are scheduled for immediate execution.   * <p>   * @param schedulerTask task to be scheduled   * @param iterator iterator that describes the schedule   * @throws IllegalStateException if task was already scheduled or cancelled, scheduler was cancelled, or scheduler thread terminated.   */      public void schedule(SchedulerTask schedulerTask,              ScheduleIterator iterator,String type) {          Date time = iterator.next(type);          if (time == null) {              schedulerTask.cancel();          } else {              synchronized(schedulerTask.lock) {                  if (schedulerTask.state != SchedulerTask.VIRGIN) {                      throw new IllegalStateException("Task already scheduled " +                          "or cancelled");                  }                  schedulerTask.state = SchedulerTask.SCHEDULED;                  schedulerTask.timerTask =                      new SchedulerTimerTask(schedulerTask, iterator,type);                  timer.schedule(schedulerTask.timerTask, time);                  //timer.scheduleAtFixedRate(schedulerTask.timerTask,time,15000);              }          }      }      private void reschedule(SchedulerTask schedulerTask,              ScheduleIterator iterator,String type) {          Date time = iterator.next(type);          if (time == null) {              schedulerTask.cancel();          } else {              synchronized(schedulerTask.lock) {                  if (schedulerTask.state != SchedulerTask.CANCELLED) {                      schedulerTask.timerTask =                          new SchedulerTimerTask(schedulerTask, iterator,type);                      timer.schedule(schedulerTask.timerTask, time);                      //timer.scheduleAtFixedRate(schedulerTask.timerTask,time,15000);                  }              }          }      }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -