下面列出了org.quartz.Scheduler#getCurrentlyExecutingJobs ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* This method runs the current job only once, right now
* @return int 0 if it's not running, 1 if it is, 2 if there is an error
*/
public int getSelectedJobRunning()
{
Scheduler scheduler = schedulerManager.getScheduler();
if (scheduler == null)
{
log.error("Scheduler is down!");
return 2;
}
try
{
List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
JobKey selected = selectedJobDetailWrapper.getJobDetail().getKey();
for (JobExecutionContext jobExecutionContext : executingJobs) {
if(selected.equals(jobExecutionContext.getJobDetail().getKey()) )
return 1;
}
return 0;
}
catch (Exception e)
{
log.error("Failed to trigger job now", e);
return 2;
}
}
public List<JobExecutionContextWrapperBean> getRunningJobs() {
List<JobExecutionContext> currentJobs = new ArrayList<JobExecutionContext>();
List<JobExecutionContextWrapperBean> currentWrappedJobs = new ArrayList<JobExecutionContextWrapperBean>();
Scheduler scheduler = schedulerManager.getScheduler();
if (scheduler == null)
{
log.error("Scheduler is down!");
}
else {
try {
currentJobs = scheduler.getCurrentlyExecutingJobs();
} catch (SchedulerException e) {
log.warn("Unable to get currently executing jobs");
}
}
for (JobExecutionContext jec : currentJobs)
{
JobExecutionContextWrapperBean jobExecutionContextWrapper = new JobExecutionContextWrapperBean(this, jec);
jobExecutionContextWrapper.setIsKillable(isJobKillable(jec.getJobDetail()));
currentWrappedJobs.add(jobExecutionContextWrapper);
}
return currentWrappedJobs;
}
/**
* This method runs the current job only once, right now
* @return int 0 if it's not running, 1 if it is, 2 if there is an error
*/
public int getSelectedJobRunning()
{
Scheduler scheduler = schedulerManager.getScheduler();
if (scheduler == null)
{
log.error("Scheduler is down!");
return 2;
}
try
{
List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
JobKey selected = selectedJobDetailWrapper.getJobDetail().getKey();
for (JobExecutionContext jobExecutionContext : executingJobs) {
if(selected.equals(jobExecutionContext.getJobDetail().getKey()) )
return 1;
}
return 0;
}
catch (Exception e)
{
log.error("Failed to trigger job now", e);
return 2;
}
}
public List<JobExecutionContextWrapperBean> getRunningJobs() {
List<JobExecutionContext> currentJobs = new ArrayList<JobExecutionContext>();
List<JobExecutionContextWrapperBean> currentWrappedJobs = new ArrayList<JobExecutionContextWrapperBean>();
Scheduler scheduler = schedulerManager.getScheduler();
if (scheduler == null)
{
log.error("Scheduler is down!");
}
else {
try {
currentJobs = scheduler.getCurrentlyExecutingJobs();
} catch (SchedulerException e) {
log.warn("Unable to get currently executing jobs");
}
}
for (JobExecutionContext jec : currentJobs)
{
JobExecutionContextWrapperBean jobExecutionContextWrapper = new JobExecutionContextWrapperBean(this, jec);
jobExecutionContextWrapper.setIsKillable(isJobKillable(jec.getJobDetail()));
currentWrappedJobs.add(jobExecutionContextWrapper);
}
return currentWrappedJobs;
}
public static List<String> getRunningJobNames(Scheduler scheduler) throws SchedulerException {
List<JobExecutionContext> jobs = scheduler.getCurrentlyExecutingJobs();
List<String> runningJobs = new ArrayList<String>();
for (JobExecutionContext job : jobs) {
runningJobs.add(job.getJobDetail().getKey().getName());
}
return runningJobs;
}
public static Map<String, JobExecutionContext> getRunningJobs(Scheduler scheduler) throws SchedulerException {
Map<String, JobExecutionContext> runningJobs = new HashMap<String, JobExecutionContext>();
List<JobExecutionContext> jobs = scheduler.getCurrentlyExecutingJobs();
for (JobExecutionContext context : jobs) {
runningJobs.put(context.getJobDetail().getKey().getName(), context);
}
return runningJobs;
}