This commit is contained in:
xueli.xue 2015-12-01 22:09:17 +08:00
parent 65243e7649
commit 9f3dd8b3a1
3 changed files with 29 additions and 14 deletions

View File

@ -1,8 +1,8 @@
package com.xxl.controller; package com.xxl.controller;
import java.util.Set; import java.util.List;
import java.util.Map;
import org.quartz.JobKey;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -16,8 +16,8 @@ public class IndexController {
@RequestMapping("index") @RequestMapping("index")
public String index(Model model) { public String index(Model model) {
Set<JobKey> list = DynamicSchedulerUtil.getJobKeys(); List<Map<String, Object>> jobList = DynamicSchedulerUtil.getJobList();
model.addAttribute("jobList", list); model.addAttribute("jobList", jobList);
return "job/index"; return "job/index";
} }

View File

@ -1,6 +1,9 @@
package com.xxl.quartz; package com.xxl.quartz;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -38,21 +41,30 @@ public final class DynamicSchedulerUtil implements InitializingBean {
} }
// getJobKeys // getJobKeys
public static Set<JobKey> getJobKeys(){ public static List<Map<String, Object>> getJobList(){
List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
try { try {
String groupName = scheduler.getJobGroupNames().get(0); String groupName = scheduler.getJobGroupNames().get(0);
return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)); Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
if (jobKeys!=null && jobKeys.size()>0) {
for (JobKey jobKey : jobKeys) {
TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
Trigger trigger = scheduler.getTrigger(triggerKey);
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
Map<String, Object> jobMap = new HashMap<String, Object>();
jobMap.put("TriggerKey", triggerKey);
jobMap.put("Trigger", trigger);
jobMap.put("JobDetail", jobDetail);
jobList.add(jobMap);
}
}
} catch (SchedulerException e) { } catch (SchedulerException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} return jobList;
public static void getJobDetail(String triggerKeyName){
// TriggerKey : name + group
String group = Scheduler.DEFAULT_GROUP;
TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group);
} }
// addJob 新增 // addJob 新增

View File

@ -29,7 +29,10 @@
<h4>在线任务:</h4> <h4>在线任务:</h4>
<#if jobList?exists && jobList?size gt 0> <#if jobList?exists && jobList?size gt 0>
<#list jobList as item> <#list jobList as item>
<p>${item}</p> <p>${item['TriggerKey']}</p>
<p>${item['Trigger']}</p>
<p>${item['Trigger'].cronExpression}</p>
<p>${item['JobDetail']}</p>
</#list> </#list>
</#if> </#if>
</div> </div>