• 社区居民
  • 忠实会员
  • 原创写手

JSF 2 + Quartz scheduling library

更多 发布于:2016-05-16 10:53
I have a web application thats using JSF 2. In this application I am using a charting library which is getting data from an xml file, the application updates the xml file, when someone accesses the site, because of jsf 2 Action. Now I want to implement the Quartz library the open source scheduling library, to update the xml file and not rely on the users action, but I have no idea how to call an Action from Quartz using JSF 2. Thanks in advance guys.

Generally speaking , you should implement your scheduled logic , define when it will run , and initialize your scheduled jobs when the application server starts. Implement scheduled logic Your scheduled class should implement org.quartz.Job interface and override its execute() which contains the logic of your scheduled job. In your case , it is the method to update the XML file. You should make this method does not have any dependencies on JSF such that it can be called outside the JSF . public class MyScheduledJob implements Job {

   public void execute(JobExecutionContext context) throws JobExecutionException {
 Initialize and start Quartz Quartz provides a ServletContextListener called QuartzInitializerListener that allows you to initialize and start Quartz when the application server starts . Add this listener to your web.xml <listener>
 By default , it will look for a file called in the classpath to initialize Quartz . You can refer this for the more info about configurable options available in Define which Job will run at which time You can define it in a XML file (Its schema definition can be found here ) and configure XMLSchedulingDataProcessorPlugin in to load this XML when Quartz is initialized. For example , in the org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml org.quartz.plugin.jobInitializer.failOnFileNotFound = true Then in the quartz-config.xml <?xml version="1.0" encoding="UTF-8"?>


                <description>Job to update XML </description>
                <job-class>com.xxxx.xxxx.xxxx.MyScheduledJob </job-class>

                            <!-- It will run every night at 3:30 am -->
                            <cron-expression>0 30 3 * * ?</cron-expression>  
 All the above is for Quartz 'a latest version 2.1 . You can check out the sample codes and tutorials from Quartz for more info.










喜欢0 评分0