Java 延迟任务:调度程序在Spring3中首次执行
我有一个简单的应用程序,它使用Spring3进行依赖注入。我有一个JFrame供用户查看,还有一些后台任务用于与后端服务器和本地数据库维护进行同步 这是我的应用程序上下文的相关部分:Java 延迟任务:调度程序在Spring3中首次执行,java,spring,Java,Spring,我有一个简单的应用程序,它使用Spring3进行依赖注入。我有一个JFrame供用户查看,还有一些后台任务用于与后端服务器和本地数据库维护进行同步 这是我的应用程序上下文的相关部分: <task:scheduler id="scheduler" pool-size="1"/> <task:scheduled-tasks scheduler="scheduler"> <task:scheduled ref="synchronizer" method="incr
<task:scheduler id="scheduler" pool-size="1"/>
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="synchronizer" method="incrementalSync" fixed-delay="600000"/>
... more tasks ...
</task:scheduled-tasks>
<bean id="mainFrame" class="nl.gdries.myapp.client.ui.MainFrame">
... properties and such ...
</bean>
... 更多任务。。。
... 属性等。。。
启动此applicationContext时,即使在加载UI时,调度程序也会立即开始执行后台任务。因为第一个任务在开始时相当繁重,所以我希望它在开始执行之前等待UI完全加载和显示
有人知道如何告诉Spring延迟执行计划的任务,直到我选择的时刻吗?这似乎被排除在
bean定义之外,我上周才注意到这一点
但是请记住,
定义只是快捷方式,您可以始终使用显式方法,通过使用嵌套的ScheduledExecutorTask
bean定义ScheduledExecutorFactoryBean
。这为您提供了更精细的控制,包括initialDelay
我遇到了相同的问题,并返回到TimerTask,与中的25.7.1点相同
我希望Spring3.1中的initialDelay属性将出现在
中,因为在Spring3.0中,TimerFactoryBean已被弃用。
您可以投票支持这个问题:jira.springframework.org/browse/SPR-7022这是通过spring 3.2中的方式引入的,因此如果您使用3.2模式,它将再次可用——例如:
通过上述操作,您可以执行以下操作:
<task:scheduler id="scheduler" pool-size="1"/>
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="synchronizer" method="incrementalSync" fixed-delay="600000" initial-delay="initial delay needed for the app to start"/>
... more tasks ...
</task:scheduled-tasks>
... 更多任务。。。
是否可以为每个任务设置动态cron参数??使用TimeFinder FactoryBean??
<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<task:scheduler id="scheduler" pool-size="1"/>
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="synchronizer" method="incrementalSync" fixed-delay="600000" initial-delay="initial delay needed for the app to start"/>
... more tasks ...
</task:scheduled-tasks>