📄 scheduler.java
字号:
package cn.js.fan.kernel;import java.util.Vector;import java.util.Iterator;public class Scheduler extends Thread { private static long updateInterval = 5000; public static long currentTime; private Vector units = new Vector(); public static Scheduler scheduler = null; public static final int DO_WORK = 1; public static final int DO_PAUSE = 2; public static final int DO_EXIT = 0; public static int action = DO_WORK; public Scheduler(long updateInterval) { this.updateInterval = updateInterval; this.setDaemon(true); this.setName("cn.js.fan.kernel.Scheduler"); start(); } public int getAction() { return action; } public static synchronized void initInstance(long updateInterval) { if (scheduler==null) scheduler = new Scheduler(updateInterval); } public void run() { while (action!=DO_EXIT) { if (action==DO_WORK) { try { currentTime = System.currentTimeMillis(); Iterator ir = units.iterator(); while (ir.hasNext()) { ISchedulerUnit isu = (ISchedulerUnit) ir.next(); isu.OnTimer(currentTime); } } catch (Throwable t) { System.out.println("run:" + t.getMessage()); t.printStackTrace(); } } try { sleep(updateInterval); } catch (InterruptedException ie) { } } System.out.println(getName() + " exit. "); } public void setUpdateInterval(long updateInterval) { this.updateInterval = updateInterval; } public synchronized void UnitsOperate(ISchedulerUnit isu, boolean AddTrueDelFalse) { if (AddTrueDelFalse) { units.addElement(isu); } else { units.remove(isu); } } public static synchronized Scheduler getInstance() { if (scheduler==null) initInstance(updateInterval); return scheduler; } public Vector getUnits() { return units; } public void ClearUnits() { units.clear(); } public void doExit() { getInstance().action = DO_EXIT; } public void doPause() { getInstance().action = DO_PAUSE; } public void doResume() { getInstance().action = DO_WORK; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -