spring quartz 定时器不运行的问题
RT 操作是想
运行的时候设置两个定时器,
比如
开始:2012-05-23 09:56:00
结束:2012-05-23 18:53:00
当开始时间到了的时候在去开启两个日常定时器
开始:08:00
结束:19:00
现在是为什么 开始:2012-05-23 09:56:00
时间到了的时候没有去开启两个日常定时器
我贴一下代码
如果要源码 可以问我拿 ,请帮忙看下是什么问题
运行的时候设置两个定时器,
比如
开始:2012-05-23 09:56:00
结束:2012-05-23 18:53:00
当开始时间到了的时候在去开启两个日常定时器
开始:08:00
结束:19:00
现在是为什么 开始:2012-05-23 09:56:00
时间到了的时候没有去开启两个日常定时器
我贴一下代码
/*
* Copyright 2005 - 2009 Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
package com.sanss.job;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MisfireExample {
public static final String SERVICE_ID = "SERVICEID";
public ApplicationContext app;
public Scheduler sched;
public void start(Service service) throws Exception {
String serviceName = service.getServiceName();
Integer serviceId = service.getServiceId();
JobDetail job = new JobDetail(serviceName + "&start", serviceName,
MyQuartzJobBean.class);
job.getJobDataMap().put(MisfireExample.SERVICE_ID, serviceId);
String startTime = service.getServiceStartDate() + " "
+ service.getSmsStartTime() + ":00"; // 开始时间
startTime = "2012-05-23 09:56:00";
CronTrigger ct = new CronTrigger(serviceName + "&start", serviceName,
getCronExpression(startTime));
System.out.println(ct.isVolatile());
sched.pauseTrigger(serviceName + "&start", serviceName);// 停止触发器
sched.unscheduleJob(serviceName + "&start", serviceName);// 移除触发器
sched.scheduleJob(job, ct); // 开始任务
sched.start();
}
public void end(Service service) throws Exception {
String serviceName = service.getServiceName();
Integer serviceId = service.getServiceId();
JobDetail job = new JobDetail(serviceName + "&end", serviceName,
MyQuartzJobBean.class);
job.getJobDataMap().put(MisfireExample.SERVICE_ID, serviceId);
String endTime = service.getServiceEndDate() + " "
+ service.getSmsEndTime() + ":00";// 结束时间
endTime = "2012-05-23 18:53:00";
CronTrigger ct = new CronTrigger(serviceName + "&end", serviceName,
getCronExpression(endTime));
System.out.println(ct.isVolatile());
sched.pauseTrigger(serviceName + "&end", serviceName);// 停止触发器
sched.unscheduleJob(serviceName + "&end", serviceName);// 移除触发器
sched.scheduleJob(job, ct); // 开始任务
sched.start();
// sched.shutdown(true);
}
public static void main(String[] args) {
try {
MisfireExample example = new MisfireExample();
example.app = new ClassPathXmlApplicationContext(
"classpath:applicationContext.xml");
example.sched = (Scheduler) example.app.getBean("quartzScheduler");
ServiceDAO serviceDAO = (ServiceDAO) example.app
.getBean("serviceDAO");
Service service = serviceDAO.findById(8665);
example.start(service);
example.end(service);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getCronExpression(String time) throws Exception {
System.out.println(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = sdf.parse(time);
int seconds = startDate.getSeconds(); // 秒
int minutes = startDate.getMinutes();// 分
int hours = startDate.getHours();// 时
int date = startDate.getDate();// 天
int month = startDate.getMonth() + 1;// 月
System.out.println(hours);
return (seconds + " " + minutes + " " + hours + " " + date + " "
+ month + " ?");
}
}
如果要源码 可以问我拿 ,请帮忙看下是什么问题
...全文
相关推荐
web定时器的实现思路
NULL 博文链接:https://bbsanwei.iteye.com/blog/266815
定时器迁移方案
定时器迁移方案,对迁移的过程步骤和注意事项都有详细的说明和配图,以及相关迁移应急回退方法,项目实用,独家发行
简单易用的java定时器scheduler,有完整配置说明
超级简单易用的java定时器,1个源程序,一个配置文件,再加一个配置项,完美搞定
spring java 定时器 执行两次 quartz
spring定时器代码。解决多次执行问题。包含quartz-all.jar包。 说明很详细。希望能帮上哪位朋友。
spring和quartz的定时器的启动和停止例子
spring和quartz的定时器的启动和停止例子


Web 开发
