gpt4 book ai didi

java - Spring,Java - 并行运行许多计划任务,每个任务都有一个实例

转载 作者:行者123 更新时间:2023-11-30 06:25:08 25 4
gpt4 key购买 nike

我尝试并行运行许多计划任务,每个任务都有一个实例我这样配置任务

<task:scheduled ref="PatchData" method="start" fixed-rate="1000"/>

但是每秒都有许多实例开始,而第一个实例尚未完成。是否可以仅配置同时运行的任务的一个实例?我在 spring-scheduler.xml 中的 bean 配置

<?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">


<bean id="UpdateScheduler" class="org.ws.scheduled.UpdateScheduler" />
<bean id="PatchData" class="org.ws.scheduled.PatchData" />

<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="UpdateScheduler" method="start" cron="0 30 14 * * *"/>
<task:scheduled ref="PatchData" method="start" fixed-rate="1000"/>

</task:scheduled-tasks>

<task:scheduler id="scheduler" pool-size="10"/>

最佳答案

您可以在bean标签中添加配置文件设置。示例:

<beans profile="scheduledProfile">
<bean id="UpdateScheduler" class="org.ws.scheduled.UpdateScheduler" />
<bean id="PatchData" class="org.ws.scheduled.PatchData" />

<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="UpdateScheduler" method="start" cron="0 30 14 * * *"/>
<task:scheduled ref="PatchData" method="start" fixed-rate="1000"/>
</task:scheduled-tasks>
<bean />

并且,在激活预定配置文件的一台计算机上启动您的应用程序 = -Dspring.profiles.active=scheduledProfile

这样,这个 Schedule 就只能在一个实例中起作用。

关于java - Spring,Java - 并行运行许多计划任务,每个任务都有一个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47330246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com