Search code examples
javaquartz-scheduler

Need to trigger a job as and when quartz scheduler starts


Quartz scheduler wont trigger my job when I start it. My job is scheduled for every hour. but after starting my scheduler, My first job is trigged after an hour. I'm new to quartz. below is my quartz launch code

    JobKey feedWSClient = new JobKey("feedWSClient", "feed-validator");
    JobDetail feedWSJob = JobBuilder.newJob(this).withIdentity(feedWSClient).build();
    Trigger feedWSCListenerTrigger = TriggerBuilder.newTrigger()
       .withIdentity("feedWSCListenerTrigger","feed-validator")
       .withSchedule(CronScheduleBuilder.cronSchedule("0 0/59 * * * ?")).build();       

    Scheduler scheduler = new StdSchedulerFactory().getScheduler();
    scheduler.scheduleJob(feedWSJob,feedWSCListenerTrigger);
    scheduler.start();

Solution

  • Below code worked for me. http://quartz-scheduler.org/api/2.2.0/

    scheduler.start();
    scheduler.triggerJob(feedWSClient);
    

    Need to call the above statement after starting the scheduler with jobkey.