spring-Quartz定时器的问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 03:14:33
我的配置文件:applicantContext.xml
<bean id="quartzClock" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>test.QuartzClock</value>
</property>
</bean>

<!-- 第二步 调度定时任务 -->
<!-- 这种配置可以精确几点执行定时任务 -->
<bean id="cronQuartzClock" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="quartzClock"></ref>
</property>
<property name="cronExpression">
<value>0 27 14 * * ?</value><!--定时在任何月份任何日期(不管星期几)的22点52分0秒 -->
<!-- 一个cron表达式有到少6个(也可能是7个)由空格分隔的时间元素.从左到右,这些元素的定义如下:
1.秒(0-59)
2.分钟(0-59)
3.小时(0-23)
4.月份中的是期(1-31)
5.月份(1-12或SUN-DEC)
6.星期中的日期(1-7或SUN-SAT)

package com.suplus.oms.workdate.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.hibernate.Session;
import org.hibernate.cfg.Configuration;

import com.suplus.oms.util.simperfect.hibernate.ThreadLocalSession;

public class ServerShutDownListener implements ServletContextListener {

public void contextDestroyed(ServletContextEvent arg0) {
}

public void contextInitialized(ServletContextEvent arg0) {

}

}

写一个listener,然后在web.xml里配上,init方法调用你定时器的启动方法。

<listener>
<listener-class>com.suplus.oms.workdate.listener.ServerShutDownListener</listener-class>
</listener>