下面列出了org.quartz.UnableToInterruptJobException#org.quartz.InterruptableJob 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Interrupt the identified InterruptableJob executing in this Scheduler instance.
*
* <p>
* This method is not cluster aware. That is, it will only interrupt
* instances of the identified InterruptableJob currently executing in this
* Scheduler instance, not across the entire cluster.
* </p>
*
* @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
*/
public boolean interrupt(String fireInstanceId) throws UnableToInterruptJobException {
List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
Job job = null;
for(JobExecutionContext jec : jobs) {
if (jec.getFireInstanceId().equals(fireInstanceId)) {
job = jec.getJobInstance();
if (job instanceof InterruptableJob) {
((InterruptableJob)job).interrupt();
return true;
} else {
throw new UnableToInterruptJobException(
"Job " + jec.getJobDetail().getKey() +
" can not be interrupted, since it does not implement " +
InterruptableJob.class.getName());
}
}
}
return false;
}
public String processActionKill() {
if (getIsKillable()) {
InterruptableJob job = (InterruptableJob)jec.getJobInstance();
try {
job.interrupt();
} catch (UnableToInterruptJobException e) {
log.error(e.getMessage(), e);
}
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO,
parentTool.rb.getFormattedMessage("kill_message",
new String[] {jec.getJobDetail().getKey().getName()}), null));
}
return "runningJobs";
}
public String processActionKill() {
if (getIsKillable()) {
InterruptableJob job = (InterruptableJob)jec.getJobInstance();
try {
job.interrupt();
} catch (UnableToInterruptJobException e) {
log.error(e.getMessage(), e);
}
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO,
parentTool.rb.getFormattedMessage("kill_message",
new String[] {jec.getJobDetail().getKey().getName()}), null));
}
return "runningJobs";
}
/**
* Interrupt all instances of the identified InterruptableJob executing in
* this Scheduler instance.
*
* <p>
* This method is not cluster aware. That is, it will only interrupt
* instances of the identified InterruptableJob currently executing in this
* Scheduler instance, not across the entire cluster.
* </p>
*
* @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
*/
public boolean interrupt(JobKey jobKey) throws UnableToInterruptJobException {
List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
JobDetail jobDetail = null;
Job job = null;
boolean interrupted = false;
for(JobExecutionContext jec : jobs) {
jobDetail = jec.getJobDetail();
if (jobKey.equals(jobDetail.getKey())) {
job = jec.getJobInstance();
if (job instanceof InterruptableJob) {
((InterruptableJob)job).interrupt();
interrupted = true;
} else {
throw new UnableToInterruptJobException(
"Job " + jobDetail.getKey() +
" can not be interrupted, since it does not implement " +
InterruptableJob.class.getName());
}
}
}
return interrupted;
}
public boolean isJobKillable(JobDetail detail) {
if (InterruptableJob.class.isAssignableFrom(detail.getJobClass())) {
return true;
}
return false;
}
public boolean isJobKillable(JobDetail detail) {
if (InterruptableJob.class.isAssignableFrom(detail.getJobClass())) {
return true;
}
return false;
}
public boolean isInterruptible(JobDetail job) {
return InterruptableJob.class.isAssignableFrom(job.getJobClass());
}