1.通过代码动态获取所有的任务,然后获取任务来判断,这种方法,在集群环境下是不好使的,
因为获取到的任务都是某个实例上的任务:
- public static boolean isJobRunning(JobExecutionContext ctx, String jobName, String groupName)
- throws SchedulerException {
- List<JobExecutionContext> currentJobs = ctx.getScheduler().getCurrentlyExecutingJobs();
-
- for (JobExecutionContext jobCtx : currentJobs) {
- String thisJobName = jobCtx.getJobDetail().getKey().getName();
- String thisGroupName = jobCtx.getJobDetail().getKey().getGroup();
- if (jobName.equalsIgnoreCase(thisJobName) && groupName.equalsIgnoreCase(thisGroupName)
- && !jobCtx.getFireTime().equals(ctx.getFireTime())) {
- return true;
- }
- }
- return false;
- }
//1.这里你还可以使用factory获取scheduler,如果没有groupName的话,只用jobName这一个参数就可以了.
2.判断某个定时任务是否是暂停的状态.
- private Boolean isJobPaused(String jobName) throws SchedulerException {
-
- JobKey jobKey = ne