I have created two jobs in Spring project which run at two different time independent to each other.
public class JobA extends QuartzJobBean
{
@Override
protected void executeInternal(JobExecutionContext arg0)throws JobExecutionException
{
// my actual work
}
}
and
public class JobB extends QuartzJobBean
{
@Override
protected void executeInternal(JobExecutionContext arg0)throws JobExecutionException
{
// my actual work
}
}
both are running fine at given time, but I need to provide some monitor functionality through which we can check whether jobs are running or not.
I came across JobListener and have seen other resources too but getting confused at the time of its implementation. I am not getting exactly how to use this listener in Spring Controller so that I can monitor both job in my jsp.
Update: I am using Quartz 1.8. How to check if any job is halted ? Is there any way we can restart any halted or broken job ?
You can easily retrieve your job trigger state
example for quartz 2.x :
// get the scheduler factory bean from the spring context
Scheduler scheduler = (Scheduler) getApplicationContext().getBean("schedulerFactoryBean");
// get the TriggerKey
TriggerKey triggerKey = TriggerKey.triggerKey("serviceCronTrigger");
// get the state from the triggerKey
TriggerState triggerState = scheduler.getTriggerState(triggerKey);
For quartz 1.8
According to the API docs, Scheduler.getTriggerState(String triggerName, String triggerGroup)
can tell you the state of a particular trigger, returning one of these constants: Trigger.STATE_NORMAL, Trigger.STATE_PAUSED, Trigger.STATE_COMPLETE, Trigger.STATE_ERROR, Trigger.STATE_BLOCKED, Trigger.STATE_NONE
// get the scheduler factory bean from the spring context
Scheduler scheduler = (Scheduler) getApplicationContext().getBean("schedulerFactoryBean");
// get the state
int state = scheduler.getTriggerState(triggerName, triggerGroup);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With