我无法弄清楚用于调度和汇集不同状态的runnables的内容(每个Runnable实例具有不同的状态)。我可以使用ScheduledExecutorFactoryBean和MethodInvokingRunnable来提供参数。但是看一下关键的ScheduledExecutorFactoryBean方法,它的设计方式是所有任务都应该从头开始。
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设置此场景。
请帮帮我。谢谢
编辑:缩短版本是:如何设置任务调度程序,以2秒的间隔运行数百个不同的线程实例(具有不同的状态)。
答案 0 :(得分:0)
这很简单,我不知道我在想什么,我没有看到它:-)
我刚刚以编程方式填充了ScheduledExecutorFactoryBean的ScheduledExecutorTask []数组,其中包含数千个任务,每个任务都有递增的延迟属性和不同的runnable。然后我就使用了工厂大豆...真的很方便的工厂大豆来自春天的家伙...