quartz的简单封装

业务需求,整理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();
   }


}


转载于:https://my.oschina.net/chenleijava/blog/111961

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值