0
我无法弄清楚用于调度和合并不同状态的可运行程序(每个Runnable实例具有不同的状态)。我可以使用ScheduledExecutorFactoryBean和MethodInvokingRunnable一起提供参数。但是请看一下关键的ScheduledExecutorFactoryBean方法,它的设计方式是所有任务都应该从头开始。Spring--调度和池化不同状态的可运行程序(每个Runnable实例有不同的状态)
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秒的间隔
我认为我可以使用AnnotationConfigApplicationContext设置ScheduledExecutorFactoryBean与多个ScheduledExecutorTasks每个具有MethodInvokingRunnable提供不同值的参数....听起来对我好 – lisak 2010-06-11 13:45:46
我的' m试图做的是安排代表http请求(每个请求具有不同的代理和目标)的线程,每个线程在前几秒后启动,其中有数千个请求,连接持续长达30秒,以便我需要它并发 – lisak 2010-06-11 15:21:44
现在我认为taskSchedulers绝对不是我想要做的事。他们应该安排一个不可变的任务/ Runnable。对 ? – lisak 2010-06-11 16:29:14