首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring上配置job

2012-11-12 
Spring下配置job没什么可说的, 今天把以前配置的一个job重新整理了下,用maven管理了。???应该说用Maven的特

Spring下配置job

没什么可说的, 今天把以前配置的一个job重新整理了下,用maven管理了。?

?

?

应该说用Maven的特性更多一些:打成的jar是可运行的, 打成的jar包里包括了运行所依赖的jar。

?

?

执行“mvn package”后, 再运行“java -jar .\target\rmn190Proj-jar-with-dependencies.jar”命令。

?

如下输出:

?

main started. and current second is: 1

job executed.current second is: 30

job executed.current second is: 35

job executed.current second is: 40

job executed.current second is: 45

job executed.current second is: 50

job executed.current second is: 55

?

?

============

关于job运行时间点,applicationContext.xml文件中有如下说明

?

??<!--?

?? ? ? ? ?1 Seconds (0–59)

2 Minutes (0–59)

3 Hours (0–23)

4 Day of month (1–31)

5 Month (1–12 or JAN–DEC)

6 Day of week (1–7 or SUN–SAT)

7 Year (1970–2099)

?? ? ? ? ? -->

?

<!-- 每隔5秒跑一次,30表示首次执行时等30秒, ?

?? ? ? ? ? 实验所得数据如下:

main started. and current second is: 1

job executed.current second is: 30

job executed.current second is: 35

job executed.current second is: 40

job executed.current second is: 45

job executed.current second is: 50

job executed.current second is: 55

job executed.current second is: 30

job executed.current second is: 35

job executed.current second is: 40

?? ? ? ? ? -->

?? ? ? ? ?<property name="cronExpression" value="30/5 * * * * ?" />

?

?

?



这样设置成false后,就可以通过如下API来有判断地启动了:

StdScheduler jobStarter =
        (StdScheduler)appContext.getBean("jobStarter");

jobStarter.start();

热点排行