error occured instantiating job to be executed in Quartz sheduler

10,751

Solution 1

Your job class has to be public. Otherwise, the JobBuilder can not read it.

public class myJob implements Job {           
    public void execute(JobExecutionContext context) throws JobExecutionException {
      System.out.println("Hello!  HelloJob is executing.");
    }
}

Solution 2

  1. Class should be public class
  2. Default constructor should be public
Share:
10,751
striker0794
Author by

striker0794

Updated on July 24, 2022

Comments

  • striker0794
    striker0794 almost 2 years
    package org.quartz;      
    import org.quartz.Scheduler;     
    import org.quartz.JobDetail;    
    import org.quartz.JobKey;    
    import org.quartz.Trigger;    
    import org.quartz.Job;    
    import org.quartz.JobExecutionContext;    
    import org.quartz.JobExecutionException;    
    import org.quartz.SchedulerException;     
    import org.quartz.impl.StdSchedulerFactory;     
    import static org.quartz.JobBuilder.*;     
    import static org.quartz.TriggerBuilder.*;     
    import static org.quartz.SimpleScheduleBuilder.*;    
    import static org.quartz.CronScheduleBuilder.*;    
    import static org.quartz.CalendarIntervalScheduleBuilder.*;    
    import static org.quartz.DateBuilder.*;    
    
    class myJob implements Job {           
        public void execute(JobExecutionContext context)    
          throws JobExecutionException
        {
          System.out.println("Hello!  HelloJob is executing.");
        }
    }
    
    public class schedule{
        public static void main(String args[]) throws Exception{    
             System.out.println("Java working");
    
             try {
                        // Grab the Scheduler instance from the Factory                 
                    JobKey jobKeyA = new JobKey("myJob", "group1");    
                    JobDetail jobA = JobBuilder.newJob(myJob.class)    
                    .withIdentity(jobKeyA).build();
    
                            // Trigger the job to run now, and then every 40 seconds
                    Trigger trigger1 = TriggerBuilder    
                            .newTrigger()    
                            .withIdentity("dummyTriggerName1", "group1")    
                            .withSchedule(
                                CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                            .build();
    
                          Scheduler scheduler = new StdSchedulerFactory().getScheduler();
    
                            // and start it off    
                          scheduler.start();
    
                            // Tell quartz to schedule the job using our trigger
    
                          scheduler.scheduleJob(jobA, trigger1);
    
    
                } catch (SchedulerException se) {                   
                    se.printStackTrace();
                }    
        }       
    }
    

    And I am getting an error of instantiating job and then obviously All triggers of Job set to ERROR state. What is the reason? and please help it is very important. provide me the answer. Error

    [ERROR] 28 Dec 03:03:30.008 PM
    DefaultQuartzScheduler_QuartzSchedulerThread
    [org.quartz.core.ErrorLogger]
    

    An error occured instantiating job to be executed. job= 'group1.myJob'

    org.quartz.SchedulerException: Problem instantiating class
    'org.quartz.myJob'  [See nested exception:
    java.lang.IllegalAccessException: Class
    org.quartz.simpl.SimpleJobFactory can not access a member of class
    org.quartz.myJob with modifiers ""]
        at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:58)
        at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:69)
        at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
        at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)
    Caused by: java.lang.IllegalAccessException: Class
    org.quartz.simpl.SimpleJobFactory can not access a member of class
    org.quartz.myJob with modifiers ""
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
        at java.lang.Class.newInstance(Class.java:436)
        at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)
        ... 3 more [INFO] 28 Dec 03:03:30.013 PM
    DefaultQuartzScheduler_QuartzSchedulerThread
    [org.quartz.simpl.RAMJobStore]
    

    All triggers of Job group1.myJob set to ERROR state.

    • Sachin Janani
      Sachin Janani over 8 years
      Can you add stack trace of the exception that you are getting?
    • striker0794
      striker0794 over 8 years
      yups....i have given the error exception
    • striker0794
      striker0794 over 8 years
      Please Provide me the solution
    • Sachin Janani
      Sachin Janani over 8 years
      Make your job class public i.e public class myJob and take it out to separate file i think it will solve the issue.Please let me know if it works
    • striker0794
      striker0794 over 8 years
      Thanks ..so much . It is running Perfectly
  • siddhusingh
    siddhusingh almost 7 years
    Great point :) Such silly things create so much of problems :) Thanks