Java Quartz scheduler – Check Job Exists

        DateTime dateTime=new DateTime();
        dateTime =dateTime.plusMinutes(1);

        JobDetail job= JobBuilder.newJob(Task1.class).withIdentity("job1","group1").build();

        System.out.println(job.getKey().toString());

        SimpleTrigger trigger= (SimpleTrigger) TriggerBuilder.newTrigger()
                .withIdentity("trigger1","group1")
                .startAt(dateTime.toDate())
                .build();


        System.out.println(String.format("Start : %s",new DateTime().toString()));
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.start();
        scheduler.scheduleJob(job, trigger);

        System.out.println(scheduler.checkExists(new JobKey("job1","group1")));

References :
http://stackoverflow.com/questions/26523285/checking-if-the-job-exists-without-looping-through-all-the-jobs

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.