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.Jobinterface 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 .Initialize and start Quartz
Quartz provides a
ServletContextListenercalled QuartzInitializerListener that allows you to initialize and start Quartz when the application server starts .Add this listener to your
web.xmlBy default , it will look for a file called
quartz.propertiesin the classpath to initialize Quartz . You can refer this for the more info about configurable options available inquartz.propertiesDefine 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
quartz.propertiesto load this XML when Quartz is initialized.For example , in the
quartz.propertiesThen in the quartz-config.xml
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.