I have been working on a scheduler engine which reads schedule Jobs from a database and schedules them which works fine however the rows in the database are just "Configuration" of certain types of job for example:
A Certain Configuration to get FTP has
host: imagineryHost1.com
post: 22
and another of the same class has
host: imagineryHost2.com
post: 21
We create two FPTjob's with their own triggers and their own separate data.
/**
BaseJob is an Abstract class extending QuartzJobBean used to handle our logging and
other requirements that need across all our jobs.
*/
public class FTPJob extends BaseJob {
/**
Called from executeInternal of QuartzJobBean
*/
@Override
public boolean execute1V(JobExecutionContext context) {
//Code to get Files from FTP.
}
}
These are scheduled using the TriggerBuilder with a cron.
If i add @DisallowConcurrentExecution is will only allow 1 instance of our FTPJob to run at any one time, However I need to to be able to run Multiple instance of FTPJob but limit it to only one instance of that particular configuration of that class.
Any leads on how to progress will be highly appreciated :)
UPDATE
Based on ftom2's answer I went digging and found TriggerListener since every job configuration has it own uniqueID it possible i could "Veto" the job from running ie.
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
try {
Iterator<JobExecutionContext> it =
context.getScheduler().getCurrentlyExecutingJobs().iterator();
boolean found = false;
while(it.hasNext()) {
JobExecutionContext job = it.next();
if(trigger.getJobKey().equals(job.getJobDetail().getKey())) {
return false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Is there any other way that is a little more built in to handle this?