在spring中管理多个job

1:spring配置文件

  <bean id="dailyjob.processor"

class="com.DailyJobProcessor">

<propertyname="dailyjobQueue">

<list>

<reflocal="rollback"/>

<reflocal="tallydone"/>

<reflocal="discountnote"/>

</list>

</property>

  </bean>

<beanid="jobdetail.factory"

        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">

    <property name="targetObject">

<refbean="dailyjob.processor"/>

</property>

<propertyname="targetMethod">

<value>process</value>

</property>

  </bean>

<beanid="trigger.jobdetail"

class="org.springframework.scheduling.quartz.SimpleTriggerBean">

<propertyname="jobDetail">

<refbean="jobdetail.factory"/>

</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(inti=0;i<dailyjobQueue.size();i++){

try{

                DailyJob job = (DailyJob) dailyjobQueue.get(i);

                job.execute();

}catch(Exceptione){

System.out.println(e.getMessage());

e.printStackTrace();

}

}

    }

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

    public List getDailyjobQueue() {

returndailyjobQueue;

    }

    public void setDailyjobQueue(List dailyjobQueue) {

this.dailyjobQueue=dailyjobQueue;

}

}

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

相关推荐