Spring - 调度和池化不同状态的可运行对象(每个可运行对象实例具有不同的状态)
我不知道使用什么来调度和池化不同状态的可运行对象(每个可运行实例具有不同的状态)。我可以将 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 秒的间隔运行数百个“不同的线程实例(具有不同的状态)”。
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());
}
}
}
}
I can't think of how to setup this scenario with ThreadPoolTaskScheduler.
Please help me out here. Thank you
EDIT: shortened version is: how to setup task scheduler that would run hundreds of "different instances of Threads (with different state) with 2 seconds interval.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很简单,我不知道我在想什么,我没有看到它:-)
我刚刚以编程方式用数千个任务填充了 ScheduledExecutorFactoryBean 的 ScheduledExecutorTask[] 数组,每个任务都具有递增的延迟属性和不同的可运行项。然后我就使用了factorybean...来自spring的家伙的非常方便的factorybean...
It's easy, I don't know what I was thinking that I didn't see it :-)
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...