本文整理汇总了Java中org.quartz.InterruptableJob类的典型用法代码示例。如果您正苦于以下问题:Java InterruptableJob类的具体用法?Java InterruptableJob怎么用?Java InterruptableJob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InterruptableJob类属于org.quartz包,在下文中一共展示了InterruptableJob类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interrupt
import org.quartz.InterruptableJob; //导入依赖的package包/类
/**
* 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;
}
示例2: stop
import org.quartz.InterruptableJob; //导入依赖的package包/类
@Override
public boolean stop(long taskRunId) {
TaskRun taskRun = taskRunDAO.get(taskRunId);
long taskId = taskRun.getTaskId();
JobExecutionContext context = runningTasks.get(taskId);
if (context == null) { // there is no task run
return false;
}
Job runningJob = context.getJobInstance();
if (runningJob instanceof InterruptableJob) {
try {
log.info("Interrupting TaskRun " + taskRunId + " for Task " + taskId);
setStatus(taskRun, Status.CANCELLING);
taskRunDAO.save(taskRun);
((InterruptableJob) runningJob).interrupt();
runningTasks.remove(taskId);
return true;
} catch (UnableToInterruptJobException e) {
log.error("Unable to interrupt TaskRun " + taskRunId + " for Task " + taskId, e);
}
}
return false;
}
示例3: processActionKill
import org.quartz.InterruptableJob; //导入依赖的package包/类
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";
}
示例4: execute
import org.quartz.InterruptableJob; //导入依赖的package包/类
@Override
public Object execute() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
for (Scheduler scheduler : schedulerManager.getSchedulers()) {
if (schedulerName != null && !scheduler.getSchedulerName().equals(schedulerName)) continue;
for (JobExecutionContext context : scheduler.getCurrentlyExecutingJobs()) {
String line = scheduler.getSchedulerName() + " - " + context.getJobInstance().getClass().getName();
System.out.println(line);
System.out.println(new String(new char[line.length()]).replace("\0", "-"));
System.out.println("Job Key Name: " + context.getJobDetail().getKey().getName());
System.out.println("Job Key Group: " + context.getJobDetail().getKey().getGroup());
System.out.println("Interruptable: " + (context.getJobInstance() instanceof InterruptableJob ? "Yes" : "No"));
//System.out.println("Thread State: " + (context.getJobInstance() instanceof StatusJob ? ((StatusJob) context.getJobInstance()).getExecuteThread().getState().toString() : "N/A"));
line = "Job Data";
System.out.println(line);
System.out.println(new String(new char[line.length()]).replace("\0", "-"));
System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(context.getJobDetail().getJobDataMap()));
if (context.getJobInstance() instanceof StatusJob) {
line = "Job Status";
System.out.println(line);
System.out.println(new String(new char[line.length()]).replace("\0", "-"));
System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(((StatusJob) context.getJobInstance()).getJobStatus()));
}
System.out.println();
}
}
return null;
}
示例5: interrupt
import org.quartz.InterruptableJob; //导入依赖的package包/类
@Override
public void interrupt() throws UnableToInterruptJobException {
if (jobBean != null && jobBean instanceof InterruptableJob) {
((InterruptableJob) jobBean).interrupt();
}
}
示例6: isJobKillable
import org.quartz.InterruptableJob; //导入依赖的package包/类
public boolean isJobKillable(JobDetail detail) {
if (InterruptableJob.class.isAssignableFrom(detail.getJobClass())) {
return true;
}
return false;
}
示例7: isInterruptible
import org.quartz.InterruptableJob; //导入依赖的package包/类
public boolean isInterruptible(JobDetail job) {
return InterruptableJob.class.isAssignableFrom(job.getJobClass());
}