Java Quartz Interview Questions & Answers

5 avg. rating (100% score) - 5879 votes

Java Quartz Interview Questions

    1. Question 1. What Are The Three Key Components To Consider When Using Java Quartz?

      Answer :

      The scheduler, job and trigger. The scheduler coordinates the execution of the job and the trigger sets up the interval and frequency with which the job will run.

    2. Question 2. How Do You Begin A Quartz Process So That It Will Start Executing Jobs?

      Answer :

      To begin a quartz process you must initiate all the components, scheduler, job and trigger, and then call the start method on the scheduler.

      1. Trigger trigger = TriggerBuilder.newTrigger().withIdentity("jcgTriggerName", "group1")
      2.   .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).build();
      3. Scheduler scheduler;
      4. scheduler = new StdSchedulerFactory().getScheduler();
      5. scheduler.start();
      6. JobKey jobKey = new JobKey("jcgJobName", "group1");
      7. JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity(jobKey).build();
      8. scheduler.scheduleJob(job, trigger);

    3. Question 3. How Do I Check The Status Of A Running Job?

      Answer :

      The JobListener will allow you to check the status of a running job.

      1. jcgScheduler.getListenerManager().addJobListener(jcgJobListener, KeyMatcher.jobKeyEquals(new JobKey("jcgJobName", "jcgJobGroup")));

    4. Question 4. How Is The Simpletrigger Used?

      Answer :

      A SimpleTrigger is used for a single execution or an execution that repeated a specific number of times over a given interval.

    5. Question 5. How Do I Customize Thread Management?

      Answer :

      I set the thread pool class and corresponding thread pool properties that fall under org.quartz.threadPool. The default thread pool is org.quartz.simpl.SimpleThreadPool.

    6. Question 6. How Is The Crontrigger Used?

      Answer :

      The CronTrigger is used to execute a job using a cron expression. A cron expression is a notation that represents a second, minute, hour, day, month, or year as well as the ways to express special characters like wildcards or ranges for the schedule.

    7. Question 7. How Do You Store Job State?

      Answer :

      The JobDataMap is used to store state that will be provided to the job when it executes.

    8. Question 8. How Do You Handle Or Prevent Concurrent Execution Of Jobs?

      Answer :

      The DisallowConcurrentExecution annotation is used to prevent concurrent execution of that same instance of jobs. The instance definition is controlled by the identifier in JobDetail.

    9. Question 9. How Do You Update The Jobdatamap Between Execution Of Jobs?

      Answer :

      Use the PersistJobDataAfterExecution annotation to update the data in JobDataMap after the job executes successfully.

    10. Question 10. What Types Of Exceptions Are Allowed From The Job Execute Method?

      Answer :

      The JobExecutionException is the only allowable exception from the job execute method

    11. Question 11. What Happens When A Scheduled Job Fails To Trigger?

      Answer :

      The misfire conditions is specific to each trigger. For the cron trigger, a misfire condition is specified in the job creation or will default to the smart policy. To customize the misfire condition specific to the cron trigger there are three options; withMisfireHandlingInstructionDoNothing, withMisfireHandlingInstructionFireAndProceed, withMisfireHandlingInstructionIgnoreMisfires.

      You can also create a custom trigger by implementing the TriggerListener interface and define the triggerMisfired method.

      1  public void triggerMisfired(Trigger trigger);

    12. Question 12. What Are Job Stores?

      Answer :

      Job stores control how data is provided to the scheduler, jobs, and triggers.

    13. Question 13. What Are Different Types Of Job Stores?

      Answer :

      There are three different types of job stores provided by quartz; RAMJobStore, JDBCJobStore and TerracottaJobStore that provided persistent job data to quartz components.

    14. Question 14. How Would You Stop A Running Job?

      Answer :

      You can stop a running job by calling interrupt on the scheduler and providing the job key. The job that you are interrupting must implement the InterruptableJob interface.

      1. sched.interrupt(job.getKey());

    15. Question 15. What Is The Jobexecutioncontext?

      Answer :

      The JobExecutionContext is passed to the execute method of an invoked job by the scheduler and it contains a handle to the scheduler, a handle to the trigger and the JobDetail.

    16. Question 16. Name A Few Of The Bundled Jobs That Quartz Provides?

      Answer :

      A few of the jobs that quartz provides for users are FileScanJob, DirectoryScanJob, NativeJob, EJB3InvokerJob, SendQueueMessageJob, SendTopicMessageJob, JmxInvokerJob and SendMailJob. Documentation on these jobs exists in the JavaDoc for the quartz-jobs-*.jar.

Popular Interview Questions

All Interview Questions

All Practice Tests

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Tutorial