How to dynamically add Quartz Job to JBoss6

I am using JBoss6 and want to dynamically create Quartz-Jobs. During job processing, the next start time will be determined (for example, after 1, 5 or 10 hours).

I did not find any solutions for this, even accessing org.quartz.Scheduler (see QuartzScheduler injection in JBoss AS 6 ).

The next problem is the creation of new work assignments, I followed the tutorial http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson02.html :

 import static org.quartz.JobBuilder.*; import static org.quartz.SimpleScheduleBuilder.*; import static org.quartz.CronScheduleBuilder.*; import static org.quartz.CalendarIntervalScheduleBuilder.*; import static org.quartz.TriggerBuilder.*; import static org.quartz.DateBuilder.*; // define the job and tie it to our HelloJob class JobDetail job = newJob(HelloJob.class) .withIdentity("myJob", "group1") // name "myJob", group "group1" .build(); // Trigger the job to run now, and then every 40 seconds Trigger trigger = newTrigger() .withIdentity("myTrigger", "group1") .startNow() .withSchedule(simpleSchedule() .withIntervalInSeconds(40) .repeatForever()) .build(); // Tell quartz to schedule the job using our trigger sched.scheduleJob(job, trigger); 

But it looks like org.quartz.JobBuilder not available for JBoss6. If I manually add a quartz dependency, you have errors on startup (problems loading classes). These artifacts are defined (without explicit use of quartz):

 <dependency> <groupId>org.jboss.jbossas</groupId> <artifactId>jboss-as-client</artifactId> <version>6.0.0.Final</version> <type>pom</type> <scope>test</scope> <exclusions> <exclusion> <groupId>org.jboss.security</groupId> <artifactId>jbosssx-client</artifactId> </exclusion> <exclusion> <groupId>org.jboss.security</groupId> <artifactId>jbosssx</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.jboss.spec</groupId> <artifactId>jboss-javaee-6.0</artifactId> <version>1.0.0.Final</version> <type>pom</type> <scope>provided</scope> </dependency> 
+1
source share
2 answers

In JBoss 6, you can access the quartz scheduler using the factory class provided in the quartz library. That should be all you need:

 import org.quartz.Scheduler; import org.quartz.impl.StdSchedulerFactory; Scheduler scheduler = new StdSchedulerFactory().getScheduler(); 

We use it in the context listener at startup to dynamically schedule tasks. NTN.

+1
source

You seem to follow the Quartz 2.0.x manual. Have you tried Quartz 1.x tutorial ?

The version introduced by JBoss 6 is Quartz 1.8.3, and there are significant changes to the Quartz 2.x API .

+1
source

Source: https://habr.com/ru/post/887671/


All Articles