读书人

在spring中治理多个job

发布时间: 2012-09-04 14:19:30 作者: rapoo

在spring中管理多个job

1:spring配置文件

?

? <bean id="dailyjob.processor"
??????? />
??????? <ref local="tallydone" />
??????? <ref local="discountnote" />
????????? </list>
??? </property>
? </bean>


? <bean id="jobdetail.factory"
??????? />
??? </property>
??? <property name="targetMethod">
????? <value>process</value>
??? </property>
? </bean>


? <bean id="trigger.jobdetail"
??????? />
??? </property>
??? <property name="startDelay">


????? <value>${time.jobstartdelay}</value>
??? </property>
??? <property name="repeatInterval">


????? <value>${time.jobrepeatinterval}</value>
??? </property>
? </bean>

?

2: DailyJobProcessor类

?

?*/
public class DailyJobProcessor implements Serializable {

??? private List dailyjobQueue;

??? public void process() {
??????? //按注入计划任务的顺序执行
??????? for (int i = 0; i < dailyjobQueue.size(); i++) {
??????????? try {
??????????????? DailyJob job = (DailyJob) dailyjobQueue.get(i);

??????????????? job.execute();
??????????? } catch (Exception e) {
??????????????? System.out.println(e.getMessage());
??????????????? e.printStackTrace();
??????????? }
??????? }
??? }

??? /******************?? Spring 注入?? *********************/

??? public List getDailyjobQueue() {
??????? return dailyjobQueue;
??? }

??? public void setDailyjobQueue(List dailyjobQueue) {
??????? this.dailyjobQueue = dailyjobQueue;
??? }
}

?

3:DailyJob 为interface 让几种job实现它

读书人网 >软件架构设计

热点推荐