Quartz作業調度

Yoo_Facku 2015-07-19 12:41:29
1.<!-- Timer schedule -->
2.
3.<!--要调度的对象-->
4.<bean id="jobBean" class="net.xsbiz.common.MakeHtml" />
5.<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
6. <property name="targetObject" ref="jobBean" />
7. <property name="targetMethod" value="execute" />
8. <!--将并发设置为false-->
9. <property name="concurrent" value="false" />
10.</bean>
11.
12.<bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
13. <property name="jobDetail" ref="jobDetail" />
14. <!--表达式,我的是每 30 执行一次-->
15. <property name="cronExpression" value="0/30 * * * * ?" />
16.</bean>
17.
18.<!-- 总管理类如果将lazy-init='false'那么容器启动就会执行调度程序 -->
19.<bean id="startQuertz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" >
20. <property name="triggers">
21. <list>
22. <!--作业调度器,list下可加入其他的调度器-->
23. <ref bean="trigger" />
24. </list>
25. </property>
26.</bean>
<!-- Timer schedule -->

<!--要调度的对象-->
<bean id="jobBean" class="net.xsbiz.common.MakeHtml" />
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="jobBean" />
<property name="targetMethod" value="execute" />
<!--将并发设置为false-->
<property name="concurrent" value="false" />
</bean>

<bean id="trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<!--表达式,我的是每 天晚上12點 执行一次-->
<property name="cronExpression" value="00 00 * * * * ?" />
</bean>

<!-- 总管理类如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" >
<property name="triggers">
<list>
<!--作业调度器,list下可加入其他的调度器-->
<ref bean="trigger" />
</list>
</property>
</bean>
web.xml:

Xml代码
1. <!-- 设置Spring的监听,项目启动时候初始化 -->
2. <listener>
3.<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
4. </listener>
5. <!-- 指定Spring配置文件的路径 -->
6. <context-param>
7. <param-name>contextConfigLocation</param-name>
8. <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
9. </context-param>
<!-- 设置Spring的监听,项目启动时候初始化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 指定Spring配置文件的路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>


MakeHtml.java :

Java代码
1.//调用的类
2[color=#FF0000].public class MakeHtml {
ChatAuthErrorCountDao chatautherrordao=new ChatAuthErrorCountDao();
3. //调用的方法
4. public void execute(){ 每天00:00清空Count
5. //需要做的事情
6. }
7.

8.[/color]
9. public static void main(String[] args) {
10.
11.
12. System.out.println("----begin---");
13.
14. ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
15.
16. // 如果配置文件中将startQuertz bean的lazy-init设置为false 则不用实例化
17.
18. context.getBean("startQuertz");
19.
20. System.out.print("----end---");
21.
22.
23. }
24.
25.}
表信息
Table名稱:CHAT_AUTH_ERROR_COUNT
字段:
CUST_ID VARCHAR2(11 BYTE) 身份證字號
AUTH_TYPE CHAR(1 BYTE) 認證方式 注:1-網銀驗證;2- OTP驗證;3- ID+生日驗證
COUNT NUMBER(2,0) 錯誤次數
execute()方法怎麼寫!
...全文
88 回复 打赏 收藏 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,407

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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