代码之家  ›  专栏  ›  技术社区  ›  prilia

Java的Spring——并行运行许多计划任务

  •  0
  • prilia  · 技术社区  · 8 年前

    我的beans配置在spring scheduler中。xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:task="http://www.springframework.org/schema/task"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                http://www.springframework.org/schema/task
                http://www.springframework.org/schema/task/spring-task-3.2.xsd">
    
        <task:executor id="executor" pool-size="5"/>
        <task:scheduler id="scheduler" pool-size="10"/>
    
        <bean id="UpdateScheduler" class="org.ws.scheduled.UpdateScheduler" />
        <bean id="PatchData" class="org.ws.scheduled.PatchData" />
    
        <task:scheduled-tasks> 
            <task:scheduled ref="UpdateScheduler" method="start" fixed-delay="1000" />
            <task:scheduled ref="PatchData" method="start" fixed-delay="5000" />
        </task:scheduled-tasks>
    
        <task:annotation-driven scheduler="scheduler" executor="executor" />
    
    </beans>
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   prilia    8 年前

    谢谢大家! 我开始使用这个配置,从这里开始运行良好 https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#scheduling-task-namespace-scheduled-tasks

    <task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="beanA" method="methodA" fixed-delay="5000" initial-delay="1000"/>
        <task:scheduled ref="beanB" method="methodB" fixed-rate="5000"/>
        <task:scheduled ref="beanC" method="methodC" cron="*/5 * * * * MON-FRI"/>