最近项目中使用Quartz来做时间调度,有的时候需要立即执行某个Quartz来测试是否配置正确,故查询了下Quartz的API得到如下方法:
前置条件是spring中 JobDetailBean 、CronTriggerBean 、ThreadSchedulerFactoryBean 等Bean已经初始化好,
获得了某一个 Scheduler 的实例句柄
- String [] groupNames = this.scheduler.getJobGroupNames();
- for(String groupName : groupNames){
- System.out.println( "groupNames = : " + groupName);
- String[] jobNames =this.scheduler.getJobNames(groupName);
- for(String jobName : jobNames){
- System.out.println("jobNames = : " + jobName);
- this.scheduler.triggerJob(jobName, groupName);
- }
- }