Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz HelloJob

Tags:

I am new to Quartz and I'm running into a compiling error. I am simply trying to get the HelloJob to run based on Quartz's Lesson 1 for Hello World. I am having trouble declaring a JobDetail with the error: The method newJob(Class<? extends Job>) in the type JobBuilder is not applicable for the arguments (Class)".

Originally, the code had 3 errors at newJob, newTrigger, and simpleSchedule was

// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)
    .withIdentity("job1", "group1")
    .build();

// Trigger the job to run now, and then repeat every 40 seconds
Trigger trigger = newTrigger()
    .withIdentity("trigger1", "group1")
    .startNow()
    .withSchedule(simpleSchedule()
            .withIntervalInSeconds(40)
            .repeatForever())            
    .build();

without JobBuilder.newJob(...), TriggerBuilder.newTrigger(...), SimpleScheduleBuilder.simpleSchedule(...). Unlike the example given, I went ahead and added the imports and attached the class calls in front of newJob, newTrigger, etc. which got rid of 2/3 errors. But it seems the error persists with

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

I have also tried replacing my job declaration with

JobDetail job = new JobDetail("job1", "group1", HelloJob.class);

but that ends with Cannot instantiate the type JobDetail and it seems like a few examples out there do this.

Will really appreciate clarification,

Thanks!

like image 266
Chandrew Avatar asked Jun 09 '11 14:06

Chandrew


People also ask

What is JobDataMap in quartz?

Holds state information for Job instances. JobDataMap instances are stored once when the Job is added to a scheduler. They are also re-persisted after every execution of StatefulJob instances. JobDataMap instances can also be stored with a Trigger .

How do I get job details in quartz?

new JobKey("jobName", "jobGroupName"); As long as your job name and job group name is the same with which you created your job, you will be able to get your job detail.

What is Jobdetail?

JobDetails are meta data related to a Job implementation, they hold a reference to the Job you want to run and allow you to provide some additional data to your Job. Conveys the detail properties of a given Job instance. JobDetails are to be created/defined with JobBuilder.

What is Jobexecutioncontext?

A context bundle containing handles to various environment information, that is given to a JobDetail instance as it is executed, and to a Trigger instance after the execution completes.


1 Answers

You need to have this line of code:

import static org.quartz.JobBuilder.*;

And then in should work. Hopefully.

Edit: AND MAKE SURE 'HELLOJOB' IMPLEMENTS JOB!!

There.

like image 130
MirroredFate Avatar answered Sep 28 '22 10:09

MirroredFate