quartz-scheduler

Schedule jobs dynamically in Quartz by watching a folder


Scheduling jobs using code is easy, but I would like to schedule jobs based on contents of a folder.

For example: I want the folder in "\MyApp\Jobs" to contain some XML files that will have the information about the IJob to be scheduled.

The thing is that I want this folder to be watched for changes (for XML files) and when a new file is found, a new IJob will be schedule using the information contained in the XML.

What should I do to implement a mechanism like this?


Solution

  • The class java.io.File has a few listFiles() methods which will list the contents of your directory. Use a FileFilter or FilenameFilter if you want to limit the filenames returned in some way. Do this in a loop with a "sleep", something like 60 seconds, to avoid chewing up all your CPU.