views:

50

answers:

1

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.

A: 

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

lisak