业务需求,整理quartz的简单封装,睡觉了
public class GameSchedulerServer {
private static final Logger logger= Log4jLogger.getLogger(GameSchedulerServer.class);
private Scheduler scheduler =null;
private GameSchedulerServer(){}
/**
* 获取 GameSchedulerServer
* @return
*/
public static GameSchedulerServer getInstance(){
return singlton.GAME_SCHEDULER_SERVER;
}
/**
* 启动定时任务
* @throws org.quartz.SchedulerException
*/
public void StartTimerTask() throws SchedulerException {
try {
SchedulerFactory schedulerFactory = new StdSchedulerFactory(config.QUARTZ_PATH);
this.scheduler = schedulerFactory.getScheduler();
this.scheduler.start();
} catch (SchedulerException e) {
logger.error("GameTaskServer start error",e);
}
}
/**
* 是否启动
* @return
* @throws org.quartz.SchedulerException
*/
public boolean isStartTimerTisk() throws SchedulerException {
return this.scheduler.isStarted();
}
/**
* 是否关闭
* @return
* @throws org.quartz.SchedulerException
*/
public boolean isShutDownTimerTisk() throws SchedulerException {
return this.scheduler.isShutdown();
}
/**
* 停止作业
* @param jobName
* @param groupName
*/
public void pauseJob(String jobName, String groupName) throws SchedulerException {
this.scheduler.pauseJob(jobName, groupName);
}
/**
* 恢复 job
* @param jobName
* @param groupName
*/
public void resumeJob(String jobName, String groupName) throws SchedulerException {
this.scheduler.resumeJob(jobName, groupName);
}
/**
* 删除指定的job
* @param jobName
* @param groupName
* @return
* @throws org.quartz.SchedulerException
*/
public boolean deleteJob(String jobName, String groupName) throws SchedulerException {
return this.scheduler.deleteJob(jobName, groupName);
}
/**
* 停止触发器
* @param triggerName
* @param group
*/
public void pauseTrigger(String triggerName,String group){
try {
this.scheduler.pauseTrigger(triggerName, group);//停止触发器
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
/**
* 重启触发器
* @param triggerName
* @param group
*/
public void resumeTrigger(String triggerName,String group){
try {
this.scheduler.resumeTrigger(triggerName, group);//重启触发器
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
/**
* 移除触发器
* @param triggerName
* @param group
* @return
*/
public boolean removeTrigdger(String triggerName,String group){
try {
this.scheduler.pauseTrigger(triggerName, group);//停止触发器
return this.scheduler.unscheduleJob(triggerName, group);//移除触发器
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
private static final class singlton{
private static final GameSchedulerServer GAME_SCHEDULER_SERVER=new GameSchedulerServer();
}
}