读书人

Spring上配置job

发布时间: 2012-11-12 12:31:57 作者: rapoo

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 (059)

2 Minutes (059)

3 Hours (023)

4 Day of month (131)

5 Month (112 or JANDEC)

6 Day of week (17 or SUNSAT)

7 Year (19702099)

?? ? ? ? ? -->

?

<!-- 每隔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();

读书人网 >软件架构设计

热点推荐