Here are the details,
I have two schedulers with @scheduled Annotation. Let's says A & B. "A" Scheduler does some job and set value in static variable using setter. I want to enable the "B" Scheduler only the static variable is set to true.
One solution, I know is to the check/validate the static variable flag in "B" scheduler and skip the further process but the scheduler checks every time based on interval specified (i.e., fixed delay).
I want to completely disable the scheduler based on static variable at run time value.
PS : I manually set the time delay between the "A" & "B" Schedulers. So "A" runs first then "B"
For Example:
Initialize.class
Configuration
EnableScheduling
public class Initialize {
public A a{
return new A();
}
public B b{
return new B();
}
}
A.class
public class A{
Scheduled(fixedDelayString = "sometime specified")
public void aProcessor(){
// Following code sets the value of static variable like staticClass.setAppVariable(true);
}
}
B.class
public class B{
Scheduled(fixedDelayString = "sometime specified")
public void bProcessor(){
// some process
}
}
static.class
public class staticClass implements Serializable{
private static volatile boolean appVariable = false;
public static boolean getAppVariable() {
return appVariable;
}
public static void setAppVariable(boolean appVariable) {
staticClass.appVariable = appVariable;
}
}
But I need to initialise the "B" class/scheduler based on the static variable if it is true.
Any help?