Quartz does not fire a simple trigger

It should be pretty simple, but I don’t see the work being done. I have a breakpoint on the execute () method of the task, the thread does not appear anywhere. I'm not wrong.

The task

class Printer implements Job{ public Printer(){ System.out.println("created printer"); } @Override public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("hi" + context.getFireTime()); } } 

Main class

 class MyClass { public static void main(String[] args) throws Throwable { Scheduler s = StdSchedulerFactory.getDefaultScheduler(); JobDetail job = newJob(Printer.class).build(); CronTrigger trigger = newTrigger() .withIdentity("a", "t") .withSchedule(cronSchedule("0/5 * * * * ?").inTimeZone(TimeZone.getDefault())) .forJob(job).build(); s.scheduleJob(job, trigger); // This prints the right date! System.out.println(trigger.getNextFireTime()); s.start(); } } 

EDIT : I found that I did not have a quartz.property file, so it was possible that threadpool for quartz was never created. Therefore, as read in the documentation , I replaced the code using StdSchedulerFactory with the following text:

 DirectSchedulerFactory.getInstance().createVolatileScheduler(10); Scheduler s = DirectSchedulerFactory.getInstance().getScheduler(); 

Guess what? Bad luck. The same effect. The application remains alive, the shooting does not work.

+7
source share
1 answer

I found a solution: changing the visibility of the class that defines the job (printer) to public will allow Quartz to access it and run it.

 public class Printer implements Job{ // just add 'public'! public Printer(){ System.out.println("created printer"); } @Override public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("hi" + context.getFireTime()); } } 

This is understandable, since only <? extends Job>.class <? extends Job>.class to the scheduler (damn why?), and not - for example - anonymous objects.

Having said that, I find it really frustrating how quartz silently disables jobs without a single error message.

+9
source

All Articles