Spring - scheduling and pooling runnables of different state (each Runnable instance has different

Posted by lisak on Stack Overflow See other posts from Stack Overflow or by lisak
Published on 2010-06-11T09:45:37Z Indexed on 2010/06/11 16:23 UTC
Read the original article Hit count: 352

Filed under:
|

Hi, 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.

© Stack Overflow or respective owner

Related posts about spring

Related posts about threadpool