Spring - 调度和池化不同状态的可运行对象(每个可运行实例具有不同的状态) [英] Spring - scheduling and pooling runnables of different state (each Runnable instance has different state)
问题描述
我不知道用什么来调度和汇集不同状态的可运行对象(每个可运行实例具有不同的状态).我可以将 ScheduledExecutorFactoryBean 与 MethodInvokingRunnable 一起使用来提供参数.但是看看关键的 ScheduledExecutorFactoryBean 方法,它的设计方式是所有任务都应该从头开始.
I can't figure out what to use for scheduling and pooling runnables of different state (each Runnable instance has different state). I could use ScheduledExecutorFactoryBean together with MethodInvokingRunnable to supply arguments. But take a look at the key ScheduledExecutorFactoryBean method, it is designed in a way that all task should start at the beginning.
protected void registerTasks(ScheduledExecutorTask[] tasks, ScheduledExecutorService executor) {
for (ScheduledExecutorTask task : tasks) {
Runnable runnable = getRunnableToSchedule(task);
if (task.isOneTimeTask()) {
executor.schedule(runnable, task.getDelay(), task.getTimeUnit());
}
else {
if (task.isFixedRate()) {
executor.scheduleAtFixedRate(runnable, task.getDelay(), task.getPeriod(), task.getTimeUnit());
}
else {
executor.scheduleWithFixedDelay(runnable, task.getDelay(), task.getPeriod(), task.getTimeUnit());
}
}
}
}
我想不出如何使用 ThreadPoolTaskScheduler 设置这个场景.
I can't think of how to setup this scenario with ThreadPoolTaskScheduler.
请帮帮我.谢谢
缩短的版本是:如何设置任务调度程序,以 2 秒的间隔运行数百个不同的线程实例(具有不同的状态).
shortened version is: how to setup task scheduler that would run hundreds of "different instances of Threads (with different state) with 2 seconds interval.
推荐答案
很简单,我不知道我在想什么,我没看到 :-)
It's easy, I don't know what I was thinking that I didn't see it :-)
我刚刚以编程方式用数千个任务填充了 ScheduledExecutorFactoryBean 的 ScheduledExecutorTask[] 数组,每个任务都有递增的延迟属性和不同的可运行对象.然后我就用了工厂豆......春天家伙真的很方便的工厂豆......
I have just programmatically filled the array ScheduledExecutorTask[] of ScheduledExecutorFactoryBean with thousands of tasks, each with incremented delay property and different runnable. Then I just used the factorybean...Really handy factorybean from spring guys...
这篇关于Spring - 调度和池化不同状态的可运行对象(每个可运行实例具有不同的状态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!