spring quartz 定时器不运行的问题

ipromise_u 2012-05-23 10:00:01
RT 操作是想
运行的时候设置两个定时器,
比如
开始: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 + " ?");
}

}







如果要源码 可以问我拿 ,请帮忙看下是什么问题
...全文
136 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ipromise_u 2012-05-23
  • 打赏
  • 举报
回复
来个人结帖 不多说

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧